-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer-test1.c
66 lines (55 loc) · 1.6 KB
/
timer-test1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* $Id: timer-test1.c 133 2013-03-10 15:15:38Z xander $
*/
/** \file timer.h
* \brief Additional timers for ROBOTC.
*
* timer.h provides additional timers for ROBOTC. Please note that there is no
* roll-over checking done at all. That means that if the program runs for more than
* around 596 hours, it will roll over and weird stuff will happen.
*
* The default number of timers is 10, but this can be changed by defining MAX_TIMERS
* before this driver is included.
*
* License: You may use this code as you wish, provided you give credit where its due.
* THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER.
*
* Changelog:
* - 0.1: Initial release
*
* \author Xander Soldaat (xander_at_botbench.com)
* \date 18 May 2010
* \version 0.1
* \example TMR-test1.c
*/
#include "drivers/timer.h"
task main () {
// Create two new timer index numbers
int timer1 = TMRnewTimer();
int timer2 = TMRnewTimer();
// Configure timer1 for 2000ms
TMRsetup(timer1, 2000);
// Configure timer2 for 5000ms
TMRsetup(timer2, 5000);
// Reset and start both timers
TMRreset(timer1);
TMRreset(timer2);
while (true) {
// If timer1 expires, make a small noise and reset it.
if (TMRisExpired(timer1)) {
PlaySound(soundBlip);
while(bSoundActive) EndTimeSlice();
TMRreset(timer1);
}
// If timer2 expires, make a small noise and reset it.
if (TMRisExpired(timer2)) {
PlaySound(soundShortBlip);
while(bSoundActive) EndTimeSlice();
TMRreset(timer2);
}
EndTimeSlice();
}
}
/*
* $Id: timer-test1.c 133 2013-03-10 15:15:38Z xander $
*/