I have a circuit with a shift register which controls 8 LEDs: http://node-ardx.org/exercises/5. In code, I created a function cycle() cycle through each LED one at a time, but this occurs too quickly on the board. How can I add a delay inside the loop so that each LED stays on for 500ms?
Here's my code:
var five = require("johnny-five"), board, shiftRegister;
board = new five.Board();
board.on("ready", function() {
shiftRegister = new five.ShiftRegister({
pins: {
data: 2,
clock: 3,
latch: 4
}
});
var bytes = [
00000001,
00000010,
00000100,
00001000,
00010000,
00100000,
01000000,
10000000,
00000000
];
function cycle() {
for ( var i = 0; i < bytes.length; i++ ) {
console.log(bytes[i]);
shiftRegister.send(bytes[i]);
}
}
this.repl.inject({
sr: shiftRegister
});
cycle();
});