Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
board.on('ready', function() {
var leds = new five.Leds([12]);
var buttons = new five.Buttons({
pins: [13],
// In case your buttons are responding to different events
// they are probably receiving the eletricity in different points.
// To solve that via code you can uncomment the option `invert`
// invert: true
});
buttons.on('press', function(button) {
var index = buttons.indexOf(button);
leds[index].on();
console.log('presssed', leds[index].pin);
});
buttons.on('release', function(button) {
var index = buttons.indexOf(button);
board.on('ready', function() {
// Number of the pin connected on the board
var pinNumbers = [12];
// Starting the LED
var leds = new five.Leds(pinNumbers);
// And here is the magic! \o/
leds.blink();
// leds.on();
// How make the LED blink every second?
// Blink accepts a number as timer parameter
// The number value is based on miliseconds
// So that, 1000 miliseconds = 1 seconds
// leds.blink(1000);
});
board.on('ready', function() {
var leds = new five.Leds([12]);
var buttons = new five.Buttons({
pins: [13],
// In case your buttons are responding to different events
// they are probably receiving the eletricity in different points.
// To solve that via code you can uncomment the option `invert`
// invert: true
});
var piezo = new five.Piezo(11);
buttons.on('press', function(button) {
var index = buttons.indexOf(button);
leds[index].on();
piezo.play({ song: 'C4' });
});
buttons.on('release', function(button) {
board.on("ready", function() {
var ledPins = [2,3,4,5,6,7,8,9];
var leds = new five.Leds(ledPins);
function oneAfterAnother() {
var delay = 1;
board.counter = 0;
for (var i = 0; i < leds.length; i++) {
var led = leds[i];
board.wait(delay,function(){
console.log(this.counter + " on")
leds[this.counter].on();
})
board.wait(delay + 200,function(){
console.log(this.counter + " off")
leds[this.counter].off();
this.counter = (this.counter + 1) % leds.length;
})
board.on('ready', function() {
leds = new five.Leds([12, 3]);
var buttons = new five.Buttons([13, 2]);
piezo = new five.Piezo(11);
buttons.on('press', function(button) {
if (buttonsSequence.length) {
var index = buttons.indexOf(button);
leds[index].on();
console.log('Pressed: button', button.pin, 'led', leds[index].pin);
piezo.play({ song: piezoSongs[index] });
}
});
buttons.on('release', function(button) {
if (buttonsSequence.length) {
var index = buttons.indexOf(button);
board.on("ready", function() {
var leds = five.Leds([3,4,5]);
var btn = five.Button(2);
btn.on("press", function() {
leds[0].off();
leds[1].on().blink(500);
leds[2].off().blink(500);
});
btn.on("release", function() {
leds[0].on();
leds[1].off().stop();
leds[2].off().stop();
});
});
board.on("ready", function() {
var leds = five.Leds([2, 3, 4]);
var tmp = new five.Thermometer({
controller: "TMP36",
pin: "A0"
});
tmp.on("change", function() {
if (this.celsius >= 22) {
leds[0].on();
} else {
leds[0].off();
}
if (this.celsius >= 24) {
leds[1].on();
} else {
leds[1].off();
board.on("ready", function() {
var leds = new five.Leds([2, 3, 4, 5, 6, 7]);
var tilt = new five.Sensor.Digital(8);
var i = 0;
this.loop(1000 * 60 * 10, function() {
leds[i].on();
i = (i + 1) % 6;
});
tilt.on("change", function() {
i = 0;
leds.off();
});
});