標(biāo)題: ESP8266中斷疑問(wèn) [打印本頁(yè)]

作者: 小楊愛學(xué)習(xí)    時(shí)間: 2022-11-5 12:57
標(biāo)題: ESP8266中斷疑問(wèn)
初學(xué)ESP8266,使用arduion IDE開發(fā),學(xué)習(xí)過(guò)程中有很多疑惑,特請(qǐng)大佬解惑:
在arduion IDE調(diào)用ticker庫(kù)來(lái)實(shí)現(xiàn)隔一段時(shí)間執(zhí)行一次函數(shù),這個(gè)計(jì)時(shí)方式是基于什么計(jì)時(shí),軟件計(jì)時(shí)器?esp8266有哪些中斷方式?查到一些資料沒有看到描述。
作者: angmall    時(shí)間: 2022-11-5 17:46
attachInterrupt() 函數(shù)
要在 Arduino IDE 中設(shè)置中斷,請(qǐng)使用 attachInterrupt() 函數(shù),該函數(shù)接受以下參數(shù):GPIO 中斷引腳、要執(zhí)行的函數(shù)的名稱和模式:
attachInterrupt(digitalPinToInterrupt(GPIO), ISR, mode);



  1. #define timeSeconds 10

  2. // Set GPIOs for LED and PIR Motion Sensor
  3. const int led = 12;
  4. const int motionSensor = 14;

  5. // Timer: Auxiliary variables
  6. unsigned long now = millis();
  7. unsigned long lastTrigger = 0;
  8. boolean startTimer = false;

  9. // Checks if motion was detected, sets LED HIGH and starts a timer
  10. ICACHE_RAM_ATTR void detectsMovement() {
  11.   Serial.println("MOTION DETECTED!!!");
  12.   digitalWrite(led, HIGH);
  13.   startTimer = true;
  14.   lastTrigger = millis();
  15. }

  16. void setup() {
  17.   // Serial port for debugging purposes
  18.   Serial.begin(115200);
  19.   
  20.   // PIR Motion Sensor mode INPUT_PULLUP
  21.   pinMode(motionSensor, INPUT_PULLUP);
  22.   // Set motionSensor pin as interrupt, assign interrupt function and set RISING mode
  23.   attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);

  24.   // Set LED to LOW
  25.   pinMode(led, OUTPUT);
  26.   digitalWrite(led, LOW);
  27. }

  28. void loop() {
  29.   // Current time
  30.   now = millis();
  31.   // Turn off the LED after the number of seconds defined in the timeSeconds variable
  32.   if(startTimer && (now - lastTrigger > (timeSeconds*1000))) {
  33.     Serial.println("Motion stopped...");
  34.     digitalWrite(led, LOW);
  35.     startTimer = false;
  36.   }
  37. }
復(fù)制代碼

作者: 小楊愛學(xué)習(xí)    時(shí)間: 2022-11-7 21:15
angmall 發(fā)表于 2022-11-5 17:46
attachInterrupt() 函數(shù)
要在 Arduino IDE 中設(shè)置中斷,請(qǐng)使用 attachInterrupt() 函數(shù),該函數(shù)接受以下參 ...

這個(gè)程序是引腳變化觸發(fā)外部中斷,我想了解ESP8266有沒有像MCU那樣的定時(shí)/計(jì)數(shù)的中斷,怎樣去配置,有沒有相關(guān)數(shù)據(jù)手冊(cè)有描述。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1