Hello everybody!
I've been struggling wit ha problem for quite a while, and hope someone can help me.
I've successfully created a interrupt that sets a flag (char) high with a certain frequency. Now I want my program to wait in a while loop until the flag is set to 1.
[...]
while(timeflag == 0){}
timeflag = 0;
[...]
But it doesn't get out of the while loop.
If I insert an operation:
it works... So I assume this means that it's somehow jumping over the condition. I tried to insert one or more NOP's (no operation) but it doesn't do the trick.
That's right. But it would be clearer to declare timeflag as a boolean and then set it true and false.
volatile boolean timeflag = false;
// then, in the ISR ...
timeflag = true;
// then, in loop() ...
while (!timeflag) // while timeflag is not true
{
}
timeflag = false;
You should also try declaring all the other variables you use in the ISR as volatile: msec, sec, minutes and hours.