找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1715|回复: 2
打印 上一主题 下一主题
收起左侧

ESP8266中断疑问

[复制链接]
跳转到指定楼层
楼主
初学ESP8266,使用arduion IDE开发,学习过程中有很多疑惑,特请大佬解惑:
在arduion IDE调用ticker库来实现隔一段时间执行一次函数,这个计时方式是基于什么计时,软件计时器?esp8266有哪些中断方式?查到一些资料没有看到描述。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:155507 发表于 2022-11-5 17:46 | 只看该作者
attachInterrupt() 函数
要在 Arduino IDE 中设置中断,请使用 attachInterrupt() 函数,该函数接受以下参数:GPIO 中断引脚、要执行的函数的名称和模式:
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 发表于 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 单片机教程网

快速回复 返回顶部 返回列表