ESP32 arduino定时器中断


hw_timer_t * timer = NULL;            //声明一个定时器


void IRAM_ATTR onTimer() {            //中断函数

  Serial.println('1');
}


void setup() {
  Serial.begin(115200);                        
  timer = timerBegin(0, 80, true);                //初始化
  timerAttachInterrupt(timer, &onTimer, true);    //调用中断函数
  timerAlarmWrite(timer, 1000000, true);        //timerBegin的参数二 80位80MHZ,这里为1000000  意思为1秒
  timerAlarmEnable(timer);                //定时器使能

//timerDetachInterrupt(timer);            //关闭定时器
}


void loop() {

}

 

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐