#include<Arduino.h>
//#include <esp32-hal-timer.h>
#define led_r 18
#define led_b 5
#define button 25
hw_timer_t * timer = NULL;
hw_timer_t * timer1 = NULL;
char flag = false;
char state = false;
void IRAM_ATTR ngat_exit(){
digitalWrite(led_b, HIGH);
flag = true;
}
void IRAM_ATTR ngat_timer(){
state = !state;
digitalWrite(led_r,state);
}
void IRAM_ATTR ngat_timer_1(){
digitalWrite(led_b, LOW);
timerAlarmDisable(timer1);
}
void setup() {
// put your setup code here, to run once:
pinMode(led_r, OUTPUT);
pinMode(led_b, OUTPUT);
pinMode(button, INPUT_PULLUP);
digitalPinToInterrupt(button);
attachInterrupt(button,ngat_exit,FALLING);
timer = timerBegin(0,40,true);
timerAttachInterrupt(timer,ngat_timer,true);
timerAlarmWrite(timer,1000000,true);
timerAlarmEnable(timer);
timer1 = timerBegin(1,40,true);
timerAttachInterrupt(timer1,ngat_timer_1,true);
timerAlarmWrite(timer1,6000000,true);
//Serial.begin(115200);
//Serial.println("Hello, ESP32!");
}
void loop() {
if(flag){
//timerWrite(timer1,0);
timerAlarmEnable(timer1);
flag = false;
}
}