I want to execute 2 different output at a certain time in seconds, one after another. And change the swap time using keyEvent. Here's the idea.
[Every 10 seconds]
1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 (20) (→ second-from timer lib.)
Display Output 1 = 1-10 second
Display Output 2 = 11-20 second, (then Output 1 again, etc)
[Every 5 seconds]
1 2 3 4 (5) 6 7 8 9 (10) 11 12 13 14 (15) 16 17 18 19 (20)(→ second-from timer lib.)
Display Output 1 = 1-5 second
Display Output 2 = 6-10 second
Display Output 1 = 11-15 second, (then Output 2 again, etc)
I've been looking for question, like Timed C Program Loop and How to use seconds (time) in C program as a counter? and I only find those with timer and clock_t. I don't plan to use timer and clock since I already use a utilTimer library to return amount of seconds in realtime. Here's the my keyEvent code :
if (key == '1' ) {
delay=10;
}
if (key == '2' ) {
delay=5;
}
if (key == '3' ) {
delay=3;
}
if (key == '4' ) {
delay=1;
}
How do I implement the time loop ? As of now for the looping I'm using mod, but using mod the output is only executed once when the value meets mod. Also it's difficult to set the maximum value of the loop since I'm running realtime. So I'm still a little bit confused and haven't achieved my goal.
for (int count = 0; true; count++) {
if (count % delay == 0) {
//push output 1 every defined delay - in seconds
}
else {
//push another output
}
}
Any advice ?
[EDIT]
I'm running a simple C program on Mac. Basically what I want to do is I want to push an output in this case a string output and an image, so after several seconds the string and image will change, repeatedly. And I want to be able to control the changing frequency using key.