Skip to content

Instantly share code, notes, and snippets.

@doug2k1
Last active October 2, 2017 12:19
Show Gist options
  • Save doug2k1/c353d28748d57e2efa4c36741ddd3d00 to your computer and use it in GitHub Desktop.
Save doug2k1/c353d28748d57e2efa4c36741ddd3d00 to your computer and use it in GitHub Desktop.
Arduino light sensor example
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