Change TRUE to FALSE every 10 seconds

I have a program that displays the month, day and year. I would like to be able to print the day of the week over it, so that every 10 seconds the display changes from one to the other. I get the month, day year to show, but it lasts only 1 second, while the day of the week, stays for 9. This is the code I have that I'm using.
1
2
3
4
show = seconds%10; // show is an int
if( show == 0 )
	which = !which;// which is a bool. Every 10 seconds,
                 // which should go from TRUE to FALSE  

How can I get it to only change at 10 second intervals? Thanks for any help.
If you run that code before increasing seconds, then you get the observed behavior. If you increase seconds before that code, it should work OK.
Thanks for heads up, webJose. I was checking seconds before the listed code, but, I found that since it was in a called function, I had bool which = TRUE at the top of it, so, each time it was called, which was being set to TRUE right after it was set to FALSE. I moved the bool definition to above int main(), and it works a lot better.
Last edited on
Well, I found a better solution, of sorts. I moved the bool which = true; back into the function. Then used this, as a check.
1
2
if( seconds >=0 && seconds <10||seconds >=20 && seconds <30||seconds >=40 && seconds <50 )
		which = false;

Now, everything runs perfectly.
If you're running this in a function that is called by a scheduler, try making which a static bool.
@Stewbond

The program has scrolling text on the screen and colors that pulsate, and while that is going on, I call the routine to update the time. The routine gets called while a box frame is is opening, the colors change and scroll, so, since the routine was being called more than once per second, my which bool changed from true to false and back, many times. I would get the weekday name and calendar date flashing back and forth five or six times every 10 seconds, till I changed it to the above method I mentioned. I'm not even sure how a static bool is any different than a standard one.
Topic archived. No new replies allowed.