Skip to content

Instantly share code, notes, and snippets.

@rmurphey
Created July 27, 2012 00:27
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rmurphey/3185390 to your computer and use it in GitHub Desktop.
Save rmurphey/3185390 to your computer and use it in GitHub Desktop.
shiftOut in javascript
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)
}
}
});
@rwaldron
Copy link

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment