I want to create a counter. Every 10 seconds I want to check the state of a switch. For example if the switch is closed then the 10 sec counter increments. If it is open it goes back to sleep, wakes up again in 10 seconds and checks the state of switch. When the count reaches e.g 100 then do something. How would I go about doing this
My attempt is:
for(int i=0;i<100;i++){
if(SW=1) {
i++;
}
else
i=0;
}
You can look at this code:
10
secondsnum
, elsereset num to 0 and go to sleep
num
has reachedMAX
value set, if equal toMAX
then do something andbreak
. (To continue the cycle comment the break in the code).