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)
}
}
});
@rmurphey
Copy link
Author

Video: https://vimeo.com/46463390

Johnny Five: https://github.com/rwldrn/johnny-five

(In fairness, I'm not using that much of Johnny Five for this particular program, but it's been a godsend for all my other Arduino exploits so far.)

@rwaldron
Copy link

The serial/usb detection still counts ;)

@rmurphey
Copy link
Author

I knew it was good for something ;)

@shiawuen
Copy link

Here is my quick hack to control on-off LEDs with Express + Socket.IO + Johnny Five

https://plus.google.com/102455075182037186148/posts/JkbhQG8Mrkg (video)

@rwaldron
Copy link

Nice!

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