Skip to content

Commit 8b7c06d

Browse files
committed
fix examples
1 parent ca6013e commit 8b7c06d

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

libraries/ESP32/examples/Timer/RepeatTimer/RepeatTimer.ino

+6-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Stop button is attached to PIN 0 (IO0)
1212
#define BTN_STOP_ALARM 0
1313

14-
hw_timer_t * timer = NULL;
14+
hw_timer_t timer = NULL;
1515
volatile SemaphoreHandle_t timerSemaphore;
1616
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
1717

@@ -38,20 +38,15 @@ void setup() {
3838
// Create semaphore to inform us when the timer has fired
3939
timerSemaphore = xSemaphoreCreateBinary();
4040

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);
4543

4644
// Attach onTimer function to our timer.
47-
timerAttachInterrupt(timer, &onTimer, true);
45+
timerAttachInterrupt(timer, &onTimer);
4846

4947
// 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);
5550
}
5651

5752
void loop() {

libraries/ESP32/examples/Timer/WatchdogTimer/WatchdogTimer.ino

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const int button = 0; //gpio to use to trigger delay
55
const int wdtTimeout = 3000; //time in ms to trigger the watchdog
6-
hw_timer_t *timer = NULL;
6+
hw_timer_t timer = NULL;
77

88
void ARDUINO_ISR_ATTR resetModule() {
99
ets_printf("reboot\n");
@@ -15,11 +15,10 @@ void setup() {
1515
Serial.println();
1616
Serial.println("running setup");
1717

18-
pinMode(button, INPUT_PULLUP); //init control pin
19-
timer = timerBegin(0, 80, true); //timer 0, div 80
20-
timerAttachInterrupt(timer, &resetModule, true); //attach callback
21-
timerAlarmWrite(timer, wdtTimeout * 1000, false); //set time in us
22-
timerAlarmEnable(timer); //enable interrupt
18+
pinMode(button, INPUT_PULLUP); //init control pin
19+
timer = timerBegin(1000000, true); //timer 1Mhz resolution
20+
timerAttachInterrupt(timer, &resetModule); //attach callback
21+
timerAlarmWrite(timer, wdtTimeout * 1000, false, 0); //set time in us
2322
}
2423

2524
void loop() {

0 commit comments

Comments
 (0)