当前位置:网站首页>ESP8266-Arduino编程实例-中断
ESP8266-Arduino编程实例-中断
2022-07-27 09:20:00 【视觉&物联智能】
中断
本文将演示如何使用 ESP8266 NodeMCU 的中断和定时器。 中断检测 GPIO 状态的变化且无需不断检查其当前值。通过使用中断,当检测到更改时,会触发事件(调用函数)。
在实例中,使用 PIR 运动传感器检测运动:当检测到运动时,ESP8266 会启动一个定时器并打开 LED 预定义的秒数。 当计时器完成倒计时,LED 会自动关闭。
1、ESP8266中断介绍
中断对于在微控制器程序中使事情自动发生很有用,并且可以帮助解决时序问题。
使用中断,您无需不断检查当前引脚值。 当检测到变化时,会触发一个事件——调用一个函数。 该函数称为中断服务程序(ISR)。
当中断发生时,处理器停止执行主程序执行任务,进入中断服务程序,中断服务程序执行完成后再返回到主程序,如下图所示。

ESP8266 支持任何 GPIO 中的中断,但 GPIO16 除外。
要创建中断,需要调用 attachInterrupt() 并将 GPIO 中断引脚、ISR(要调用的函数)和模式作为参数传递。 ISR 函数必须声明 ICACHE_RAM_ATTR 属性。 模式可以是 CHANGE、RISING 或 FALLING。
边栏推荐
- [C language - zero foundation lesson 8] circular structure and break continue
- Transpose and inverse of [linear algebra 01] matrix
- 6S parameters
- JS call and apply
- [cloud co creation] Huawei cloud: full stack technology innovation, deep digitalization, leading cloud native
- [leetcode -- the second day of introduction to programming ability] operator (the number of bit 1 / the difference between the sum of the products of integers)
- Install Oracle under Linux, connect local pl/sql to Oracle import table under Linux, and create new user and password
- 工程材料知识点总结(全)
- BGP federal experiment
- 七月集训(第26天) —— 并查集
猜你喜欢

NCCL 集合通信--Collective Operations

JS call and apply

Sentry 2 orbital data download

BGP联邦实验
![[C language _ study _ exam _ review lesson 3] overview of ASCII code and C language](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[C language _ study _ exam _ review lesson 3] overview of ASCII code and C language

Linux Installation and remote connection MySQL records

【无标题】

Is the operation of assigning values to int variables atomic?

Restful

NCCL (NVIDIA Collective Communications Library)
随机推荐
Binary tree traversal
2022软件测试面试题 200道大厂面试真题 刷完拿到10k职位
Restful
BGP的社团属性
Run uni app project in hbuilder wechat applet
Size limit display of pictures
The fifth day of learning C language
基于restful页面数据交互
ArkUI开发框架组件的生命周期
ArkUI中的显式动画
[leetcode -- the second day of introduction to programming ability] operator (the number of bit 1 / the difference between the sum of the products of integers)
ES6 new - array part
Explicit animation in arkui
【树莓派】Box相关手册-4 Web代理
全排列递归思路整理
The lifecycle of arkui development framework components
The difference between computed and watch
linux下安装oracle,本地PL/SQL连接Linux下的oracle导入表并新建用户和密码
NPM install error forced installation
Wechat applet 5 - foundation strengthening (not finished)