int button = 4;
int counter = 0;
hw_timer_t *Timer0_Cfg = NULL;
void IRAM_ATTR interrupt_routine() {
Serial.println(counter++);
}
void setup() {
Serial.begin(115200);
Timer0_Cfg = timerBegin(1, 80, true);
timerAttachInterrupt(Timer0_Cfg, &interrupt_routine, true);
timerAlarmWrite(Timer0_Cfg, 500000, true);
timerAlarmEnable(Timer0_Cfg);
pinMode(button, INPUT_PULLUP);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_4, HIGH);
}
void loop() {
if (millis() > 5000) {
Serial.println("Sleep...");
delay(500);
Serial.flush();
esp_deep_sleep_start();
}
}