I'm trying to write a simple LED animation for a 7-segment display. It will light up a segment, then another one, then another one, until all are lit up, then dim a segment, then dim another one, etc. The code is (supposed to be) very simple. For reference, I'm using an MDBT42Q module with a 32khz crystal added on P0 and P1 with 22pf caps. I don't think it should affect my code.
var segs = [A, B, C, D, E, F]; // array of LED segments, each a variable for a pin
for (int i=0; i<6; i++) {
digitalWrite(segs[i], 1); // light up the first segment in segs[]
digitalPulse(D30, 0, 100); // pulse unused pin for 100ms, this is just a simple delay
}
for (int x=5; x>=0; x--) {
digitalWrite(segs[i], 0);
digitalPulse(D30, 0, 100);
}
and well, the code works as if the digitalPulse()es aren't even there. Everything happens very quickly so the LEDs just light up and off in a fraction of a second. I honestly have no idea why this isn't working as the other digitalPulses in the rest my code work just fine. I have other LED animations that use digitalPulse() in my code and those animations have no problem.
So I tried using setTimeout(). I believe it's like so, but I might be wrong:
for (var i = 0; i<6; i++) {
setTimeout('digitalWrite(segs[i], 0)', 100);
}
for (var x = 5; x>=0; x--) {
setTimeout('digitalWrite(segs[x], 1)', 100);
}
this one doesn't work either. So I tried another method:
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi,
I'm trying to write a simple LED animation for a 7-segment display. It will light up a segment, then another one, then another one, until all are lit up, then dim a segment, then dim another one, etc. The code is (supposed to be) very simple. For reference, I'm using an MDBT42Q module with a 32khz crystal added on P0 and P1 with 22pf caps. I don't think it should affect my code.
and well, the code works as if the digitalPulse()es aren't even there. Everything happens very quickly so the LEDs just light up and off in a fraction of a second. I honestly have no idea why this isn't working as the other digitalPulses in the rest my code work just fine. I have other LED animations that use digitalPulse() in my code and those animations have no problem.
So I tried using setTimeout(). I believe it's like so, but I might be wrong:
this one doesn't work either. So I tried another method:
And same results.
This has been driving me absolutely bonkers for the past few hours so any help would be greatly appreciated!