sample: custom timers/alarms the easy way

Topics on software tools like TileStudio, comments on documentation and tutorials (or the lack of) should go here.
Post Reply
User avatar
schepers_cp
Posts: 125
Joined: Tue Feb 04, 2014 9:48 pm
Location: netherlands
Contact:

sample: custom timers/alarms the easy way

Post by schepers_cp »

hey all, to get people starting coding with timers and alarms here's a simple sampleon them.

Code: Select all

// i assume you use WaitVsync(1), so the fps is set to 60, so set the counter to 60
#define FPS_SEC 60
unsigned int counter_one_sec = FPS_SEC; //the actual counter variable

int main(){
	ClearVram();
	while(1) {
		WaitVsync(1); //needed for the counter to work properly
		if (counter_one_sec < 1) {
			//do the stuff you like every second

			
			//reset the value on the counter, it is advisable to keep it in here to re-run it every second
			//use this elsewhere in your code to actually create an alarm that goes off 1 second after the event happened
			counter_one_sec = FPS_SEC;
		}
		//decrease the value by 1 if it's more than 0
		if (counter_one_sec > 0)
			counter_one_sec--;
		}
	}
}
Post Reply