ESP32 定时器 基于arduino

 

1s定时中断一次,暂时记录,有待解决问题,后续更新,不过能用,可以定时时间可长不可短


#define BTN_STOP_ALARM    0
int isrCounter=0;
hw_timer_t * timer = NULL;

void ARDUINO_ISR_ATTR onTimer(){
  isrCounter++; 
    Serial.print("onTimer no. ");
    Serial.print(isrCounter);
    Serial.println(" at ");
}

void setup() {
  Serial.begin(115200);

  // Set BTN_STOP_ALARM to input mode
  pinMode(BTN_STOP_ALARM, INPUT);


  timer = timerBegin(0, 80, true);

  // Attach onTimer function to our timer.
  timerAttachInterrupt(timer, &onTimer, true);

  // Set alarm to call onTimer function every second (value in microseconds).
  // Repeat the alarm (third parameter)
  timerAlarmWrite(timer, 500000, true);

  timerAlarmEnable(timer);
}

void loop() {
  // If Timer has fired
  


  // If button is pressed

}

 

posted @ 2025-04-30 14:45  ahao攻城狮  阅读(147)  评论(0)    收藏  举报