Created
July 22, 2013 19:14
-
-
Save olizilla/6056710 to your computer and use it in GitHub Desktop.
A johnny-five, event based, traffic light disco for your Arduino. An array of lights flash in majestic sequence for your gyratory pleasure. Each light's shining heralds it's own destruction, each extinction seeds a new.
Just like the traffic light eyeball cannons of your friendly neighbourhood mobile DJ
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
/* | |
====================================================================================================================================== | |
= ==================== ===== =================== =================== ================ =========================== | |
==== ====================== == === == ================== =================== ================ ==== ========================== | |
==== ====================== ======= ====================== =================== ====== ======== ==== ========================== | |
==== ===== = ==== === ===== ===== === ======== ======== === === ===== ======= ==== == === ==== ==== == | |
==== ===== = == = === ======= ========== = ======= ============ = == ==== ======== ==== ====== = == = == = | |
==== ===== ========== === ======= ====== == ========== ======== === == = === ======== ==== == === ==== ===== = = | |
==== ===== ======== === ======= ====== == ========== ======== ===== == = === ======== ==== == ==== === ===== = = | |
==== ===== ======= = === ======= ====== == = ======= ======== == = == = === ======== ==== == == = == = == = = | |
==== ===== ======== === ======= ====== === ======== == === === = === ======= === === ==== ==== == | |
====================================================================================================================================== | |
A johnny-five, event-based, traffic-light disco. | |
*/ | |
var five = require("johnny-five"); | |
var temporal = require("temporal"); | |
var freq = 500; | |
five.Board().on("ready", function () { | |
var lights = [ | |
new five.Pin({addr:10}), | |
new five.Pin({addr:11}), | |
new five.Pin({addr:12}) | |
]; | |
lights.forEach(function (light, index) { | |
light.on("high", function () { | |
var nextLight = lights[(index + 1) % lights.length]; | |
console.log( "Event emitted for:", "high", "on", this.addr); | |
temporal.delay(freq, function() { | |
light.low(); | |
nextLight.high(); | |
}); | |
}); | |
}); | |
// BEGIN THE DANCE OF THE LEDS! | |
lights[0].high(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LIVE LIVE LIVE: http://instagram.com/p/cFVNtmJxlc/