Page 1 of 1

sample: custom timers/alarms the easy way

Posted: Sat May 10, 2014 2:15 pm
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--;
		}
	}
}