Skip to content

Instantly share code, notes, and snippets.

@olizilla
Created July 22, 2013 19:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olizilla/6056710 to your computer and use it in GitHub Desktop.
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
/*
======================================================================================================================================
= ==================== ===== =================== =================== ================ ===========================
==== ====================== == === == ================== =================== ================ ==== ==========================
==== ====================== ======= ====================== =================== ====== ======== ==== ==========================
==== ===== = ==== === ===== ===== === ======== ======== === === ===== ======= ==== == === ==== ==== ==
==== ===== = == = === ======= ========== = ======= ============ = == ==== ======== ==== ====== = == = == =
==== ===== ========== === ======= ====== == ========== ======== === == = === ======== ==== == === ==== ===== = =
==== ===== ======== === ======= ====== == ========== ======== ===== == = === ======== ==== == ==== === ===== = =
==== ===== ======= = === ======= ====== == = ======= ======== == = == = === ======== ==== == == = == = == = =
==== ===== ======== === ======= ====== === ======== == === === = === ======= === === ==== ==== ==
======================================================================================================================================
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();
});
@olizilla
Copy link
Author

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