-
-
Save piatra/3186566 to your computer and use it in GitHub Desktop.
shiftOut in javascript
This file contains 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
var five = require("johnny-five"), | |
board; | |
board = new five.Board(); | |
board.on("ready", function() { | |
(new five.Led(13)).on(); | |
var dataPin = 2; | |
var clockPin = 3; | |
var latchPin = 4; | |
var value = 0; | |
next(value); | |
function next(i) { | |
board.digitalWrite(latchPin, board.firmata.LOW); | |
shiftOut(dataPin, clockPin, i); | |
board.digitalWrite(latchPin, board.firmata.HIGH); | |
if (++i > 255) { | |
return; | |
} | |
setTimeout(function() { | |
next(i); | |
}, 500); | |
} | |
function shiftOut(dataPin, clockPin, value) { | |
// much thanks to http://www.sqlskills.com/blogs/paulselec/post/Arduino-figuring-out-shift-registers.aspx | |
for (var mask = 128; mask > 0; mask = mask >> 1) { | |
board.digitalWrite(clockPin, board.firmata.LOW); | |
board.digitalWrite( | |
dataPin, board.firmata[ value & mask ? 'HIGH' : 'LOW' ] | |
); | |
board.digitalWrite(clockPin, board.firmata.HIGH) | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment