欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1650|回復: 2
收起左側

ESP8266中斷疑問

[復制鏈接]
ID:1006697 發表于 2022-11-5 12:57 | 顯示全部樓層 |閱讀模式
初學ESP8266,使用arduion IDE開發,學習過程中有很多疑惑,特請大佬解惑:
在arduion IDE調用ticker庫來實現隔一段時間執行一次函數,這個計時方式是基于什么計時,軟件計時器?esp8266有哪些中斷方式?查到一些資料沒有看到描述。
回復

使用道具 舉報

ID:155507 發表于 2022-11-5 17:46 | 顯示全部樓層
attachInterrupt() 函數
要在 Arduino IDE 中設置中斷,請使用 attachInterrupt() 函數,該函數接受以下參數:GPIO 中斷引腳、要執行的函數的名稱和模式:
attachInterrupt(digitalPinToInterrupt(GPIO), ISR, mode);

1.png

  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. }
復制代碼
回復

使用道具 舉報

ID:1006697 發表于 2022-11-7 21:15 | 顯示全部樓層
angmall 發表于 2022-11-5 17:46
attachInterrupt() 函數
要在 Arduino IDE 中設置中斷,請使用 attachInterrupt() 函數,該函數接受以下參 ...

這個程序是引腳變化觸發外部中斷,我想了解ESP8266有沒有像MCU那樣的定時/計數的中斷,怎樣去配置,有沒有相關數據手冊有描述。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表