esp32-clickwheel/lib/Button2/examples/ESP32TimerInterrupt/ESP32TimerInterrupt.ino
2024-03-06 12:40:28 +01:00

52 lines
1.2 KiB
C++

/////////////////////////////////////////////////////////////////
#if !defined(ESP32)
#error This sketch needs an ESP32
#else
/////////////////////////////////////////////////////////////////
#include "Button2.h"
/////////////////////////////////////////////////////////////////
#define BUTTON_PIN 39
/////////////////////////////////////////////////////////////////
Button2 btn;
hw_timer_t *timer = NULL;
/////////////////////////////////////////////////////////////////
void IRAM_ATTR onTimer() {
btn.loop();
}
/////////////////////////////////////////////////////////////////
void click(Button2 &b) {
Serial.println("click");
}
/////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
btn.begin(BUTTON_PIN);
btn.setTapHandler(click);
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &onTimer, true);
timerAlarmWrite(timer, 10000, true); // every 0.1 seconds
timerAlarmEnable(timer);
}
/////////////////////////////////////////////////////////////////
void loop() {
}
/////////////////////////////////////////////////////////////////
#endif
/////////////////////////////////////////////////////////////////