Last active
October 2, 2017 12:19
-
-
Save doug2k1/c353d28748d57e2efa4c36741ddd3d00 to your computer and use it in GitHub Desktop.
Arduino light sensor example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const five = require('johnny-five') | |
const board = new five.Board() | |
board.on('ready', () => { | |
console.log('ready!') | |
const led = new five.Led(11) | |
const photoResistor = new five.Sensor({ | |
pin: 'A2', | |
freq: 100 | |
}) | |
photoResistor.on('data', function () { | |
const resistance = this.value | |
const brightness = Math.min(Math.max(0, (resistance - 700) / 300 * 255), 255) | |
led.brightness(brightness) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment