I made a countdown program with a loop within a loop.
I want to check the state if a button is pressed, but because my countdown happens at 1 second at a time, I can only 'refresh' to check that parameter every second and not immediately when pressed. Is there a way to have different timings or delays happening at the same time?
Thanks
for (int minutes = 59; minutes >=0; minutes--){ //For every time the next loop reaches 0, minutes goes minues 1, till minutes reaches 0)
for (int seconds = 59; seconds >= 0; seconds--) { //every loop makes seconds go minues 1 till it reaches 0)
Mrightnumber = minutes %10;
Mleftnumber = (minutes/10) %10;
Srightnumber = seconds %10;
Sleftnumber = (seconds/10) %10;
LED.sendDigits(Mleftnumber,Mrightnumber,Sleftnumber,Srightnumber,1);
val = digitalRead (button); // read input value
if (val == 1) { // check if the button is pressed
delay(50); // debounce time
minutes = minutes -5;} // makes minutes goes -5
delay(1000); // Value must be 1000 ms = 1 sec.
}