Hey,
I have got a question about the "Multitasking" with an arduino.
I have a Board with some Leds which can be toggled on and off with switches.
If toggled on the LEDs blink in an interval.
I realized it with the millis() function and a time that gets updated every time the function is circled.
The Problem is, when i haven't pushed the button for a longer time the LEDs blink very fast.
How can that problem be solved?, I think it is because the timer that checks if a blinking cycle is finished didn't get updated for a long time.
Here is the Code Example:
//Blinking 6 Leds
if(Button2State == 1){
if(millis() > time_led6 + period_led6){
for(int i=2; i<8; i++){
leds6 = random(0,2);
if(leds6 == 0){
datArray[0] &= ~(1 << i);
}
else datArray[0] |= (1 << i);
time_led6 += period_led6;
}
}
}else{
for(int i=2; i<8; i++){
datArray[0] &= ~(1 << i);
}
}