Created
July 27, 2012 00:27
-
-
Save rmurphey/3185390 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) | |
} | |
} | |
}); |
The serial/usb detection still counts ;)
I knew it was good for something ;)
Here is my quick hack to control on-off LEDs with Express + Socket.IO + Johnny Five
https://plus.google.com/102455075182037186148/posts/JkbhQG8Mrkg (video)
Nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.)