11
11
// Stop button is attached to PIN 0 (IO0)
12
12
#define BTN_STOP_ALARM 0
13
13
14
- hw_timer_t * timer = NULL ;
14
+ hw_timer_t timer = NULL ;
15
15
volatile SemaphoreHandle_t timerSemaphore;
16
16
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
17
17
@@ -38,20 +38,15 @@ void setup() {
38
38
// Create semaphore to inform us when the timer has fired
39
39
timerSemaphore = xSemaphoreCreateBinary ();
40
40
41
- // Use 1st timer of 4 (counted from zero).
42
- // Set 80 divider for prescaler (see ESP32 Technical Reference Manual for more
43
- // info).
44
- timer = timerBegin (0 , 80 , true );
41
+ // Set timer frequency to 1Mhz
42
+ timer = timerBegin (1000000 , true );
45
43
46
44
// Attach onTimer function to our timer.
47
- timerAttachInterrupt (timer, &onTimer, true );
45
+ timerAttachInterrupt (timer, &onTimer);
48
46
49
47
// Set alarm to call onTimer function every second (value in microseconds).
50
- // Repeat the alarm (third parameter)
51
- timerAlarmWrite (timer, 1000000 , true );
52
-
53
- // Start an alarm
54
- timerAlarmEnable (timer);
48
+ // Repeat the alarm (third parameter) with unlimited count = 0 (fourth parameter).
49
+ timerAlarmWrite (timer, 1000000 , true , 0 );
55
50
}
56
51
57
52
void loop () {
0 commit comments