Skip to content

Instantly share code, notes, and snippets.

@julianduque

julianduque/leds.js

Created Apr 23, 2014
Embed
What would you like to do?
LEDs desde FIrebase
var five = require('johnny-five');
var Firebase = require('firebase');
var board = new five.Board();
var db = new Firebase('https://coderise.firebaseio.com');
var leds = db.child('leds');
leds.child('verde').set(0);
leds.child('rojo').set(0);
board.on('ready', function () {
var ledVerde = new five.Led(7);
var ledRojo = new five.Led(8);
leds.on('child_changed', function (snapshot) {
var led;
var name = snapshot.name();
var value = snapshot.val();
if (name === 'rojo') {
led = ledRojo;
} else if (name === 'verde') {
led = ledVerde;
} else {
return;
}
if (value === 1) {
led.on();
} else {
led.off();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.