3x3x3 LED Cube in Javascript
olav — Sun, 06/13/2010 - 20:46
The other day I built a 3×3×3 LED cube, following the excellent instructable by gzip . Now that I have drifted away a little bit from the Arduino platform, and, mostly for the ridiculously cheap PICAXE-08M, have looked into the PICAXE platform, I have decided to port my LED cube over to a 3V PICAXE-20X2 microcontroller.
Before doing that, I wanted to more thoroughly understand the procedural approach to LED patterns that gzip used in his design, so I programmed a litte LED cube simulator in Javascript:
The biggest challenge were the delay() calls in the original software. There is no such thing as a delay() function in Javascript. Sure, there are some clever solutions out there like using a modal dialog, but I found using the standard setInterval() to be quite enough. There is one tricky piece in the code where I want to run a longer sequence from within the regular 500ms ticks. For this, I kill the overall timer, run the sequence, and finally restart the overall timer in a callback to the sequence() routine:
function animations() {
clearTimeout(timer);
cube.sequence([ /* ... */ ], function() {
timer = setInterval(function() { animations(cube); }, 500)
}, 100);
}
and
cube.prototype.sequence = function(seq, onfinish, delay) {
var timer = setInterval(function() {
// ... some clever sequencing here
clearTimeout(timer);
onfinish();
}, delay);
}
Btw., I haven’t found an LED cube using a PICAXE microcontroller and would be grateful for any hints.




Kommentiert
11 weeks 6 days ago
13 weeks 3 days ago
13 weeks 4 days ago
17 weeks 2 days ago
49 weeks 5 days ago
1 year 20 weeks ago
1 year 28 weeks ago
1 year 39 weeks ago
1 year 46 weeks ago
2 years 6 days ago