No, the example of 4-20000 LEDs was just that: an example. I know I can change the brightness of the 4 LEDs I have via setting the duty cycle via setInterval(). No issues. CPU power is enough even for updating once in 5ms per LED.
I am quite confident thatI cannot do the same if I had 20000 LEDs. The question was: how do I know when the CPU won't be able to catch up anymore?
And the setBusyIndicator() does that.
BTW, I checked and this is the result:
// Glow 4 LEDs
var glow=function(led) {
var intensity=0;
var dir=1.0;
var this_led=led;
function intensity_step(n) {
intensity+=dir*n;
if (intensity>=1.0) {
intensity=1.0;
dir=-dir;
}
if (intensity<=0.0) {
intensity=0;
dir=-dir;
}
analogWrite(this_led, intensity);
}
return intensity_step;
};
var led1=glow(D13);
setInterval(function() {
led1(0.01);
}, 2);
var led2=glow(D14);
setInterval(function() {
led2(0.01);
}, 2);
var led3=glow(D12);
setInterval(function() {
led3(0.01);
}, 2);
var led4=glow(D15);
setInterval(function() {
led4(0.01);
}, 2);
// See how busy the CPU is
setBusyIndicator(D11);
Attached the wave form of D11 when changing only one LED. You can see this is repeating at 500Hz, and it's already using 25% of CPU.
4 of those keep the CPU close to 100%.
Please no one comment on the horrible code. I'm just learning JavaScript and I already figured out the code is sub-optimal in so many ways ^_^
PS: Forgot to mention: This is on the STM32F4 Discovery board.
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.
No, the example of 4-20000 LEDs was just that: an example. I know I can change the brightness of the 4 LEDs I have via setting the duty cycle via setInterval(). No issues. CPU power is enough even for updating once in 5ms per LED.
I am quite confident thatI cannot do the same if I had 20000 LEDs. The question was: how do I know when the CPU won't be able to catch up anymore?
And the setBusyIndicator() does that.
BTW, I checked and this is the result:
Attached the wave form of D11 when changing only one LED. You can see this is repeating at 500Hz, and it's already using 25% of CPU.
4 of those keep the CPU close to 100%.
Please no one comment on the horrible code. I'm just learning JavaScript and I already figured out the code is sub-optimal in so many ways ^_^
PS: Forgot to mention: This is on the STM32F4 Discovery board.
1 Attachment