本站改版新增arduino频道
ESP32C3 定时器控制LED闪烁
#define PIN_LED1 12 #define PIN_LED2 13 hw_timer_t * timer = NULL; hw_timer_t * timer2 = NULL; void ARDUINO_ISR_ATTR onTimer(){ Serial.println("00000"); digitalWrite(PIN_LED1, !digitalRead(PIN_LED1)); } void ARDUINO_ISR_ATTR onTimer2(){ Serial.println("111111"); digitalWrite(PIN_LED2, !digitalRead(PIN_LED2)); } void setup() { Serial.begin(115200); pinMode(PIN_LED1, OUTPUT); pinMode(PIN_LED2, OUTPUT); Serial.print("Timer"); // Set timer frequency to 1Mhz timer = timerBegin(1000000); timerAttachInterrupt(timer, &onTimer); timerAlarm(timer, 5000*1000, true, 0); timer2 = timerBegin(1000000); timerAttachInterrupt(timer2, &onTimer2); timerAlarm(timer2, 3000*1000, true, 1); } void loop() { // Serial.println(" ms"); delay(1000); }
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0092840194702148 seconds