找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1487|回復: 2
打印 上一主題 下一主題
收起左側(cè)

ESP8266中斷疑問

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1006697 發(fā)表于 2022-11-5 12:57 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
初學ESP8266,使用arduion IDE開發(fā),學習過程中有很多疑惑,特請大佬解惑:
在arduion IDE調(diào)用ticker庫來實現(xiàn)隔一段時間執(zhí)行一次函數(shù),這個計時方式是基于什么計時,軟件計時器?esp8266有哪些中斷方式?查到一些資料沒有看到描述。
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發(fā)
ID:155507 發(fā)表于 2022-11-5 17:46 | 只看該作者
attachInterrupt() 函數(shù)
要在 Arduino IDE 中設置中斷,請使用 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. }
復制代碼
回復

使用道具 舉報

板凳
ID:1006697 發(fā)表于 2022-11-7 21:15 | 只看該作者
angmall 發(fā)表于 2022-11-5 17:46
attachInterrupt() 函數(shù)
要在 Arduino IDE 中設置中斷,請使用 attachInterrupt() 函數(shù),該函數(shù)接受以下參 ...

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

使用道具 舉報

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

本版積分規(guī)則

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

Powered by 單片機教程網(wǎng)

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