Arduino中断处理程序及常用开发板中断引脚总览

Arduino 专栏收录该内容
¥59.90 ¥99.00
95篇文章

中断是在Arduino开发中常用的一种技术,它可以帮助我们实时响应外部事件,而无需不断轮询输入。本文将介绍Arduino中断处理程序的基本原理,并提供常见的Arduino开发板中断引脚总览。下面我们将逐步详细介绍。

  1. Arduino中断处理程序基础知识

在Arduino中,中断处理程序是在特定事件发生时自动触发的一段代码。它可以插入到正在执行的代码中,以响应外部事件,例如按下按钮、接收到数据或传感器状态的改变。

中断处理程序通常包括以下几个关键部分:

  • 中断服务函数(ISR):这是中断处理程序的核心部分,即实际执行的代码。当中断事件发生时,控制将转移到ISR中执行特定的操作。
  • 中断触发条件:这是指导致中断事件发生的条件。例如,按钮按下、电平变化或定时器溢出等。
  • 中断配置:在Arduino中,我们需要配置中断引脚和中断触发条件。这可以在设置代码中完成。
  1. 常用Arduino开发板中断引脚总览

以下是一些常见的Arduino开发板及其支持的中断引脚:

  • Arduino Uno:

    • 中断引脚 2: 使用外部中断 0
    • 中断引脚 3: 使用外部中断 1
  • Arduino Mega 2560:

    • 中断引脚 2: 使用外部中断 0
    • 中断引脚 3: 使用外部中断 1
    • 中断引脚 18: 使用外部中断 5
Arduino程序设计(五)按键中断+按键状态检测 本文主要介绍两种按键检测实验,分别是:1、外部中断实现按键控制LED灯;2、按键单击、双击和长按的状态检测。 阅读详情

相关推荐

Arduino 语法、函数使用、最常用函数、arduino教程、arduino笔记、参考手册

函数部分 数字 I/O pinMode() 描述 将指定的引脚配置成输出或输入。详情请见digital pins。 语法 pinMode(pin, mode) 参数 pin:要设置模式的引脚 mode:INPUT或OUTPUT 返回 无 例子 ledPin = 13 // LED连接到数字脚13 void setup() { pinMode(ledPin,OUTPUT); //设置数字脚为输...

mbs706的博客 1万+

Arduino学习笔记:串口中断

实习任务需要实现一个优先级变换,因此在此要自学一下串口中断。 1 为何要中断 计算机读取信息有两种方法:查询和中断。查询即为不断读取,直到得到数据。而中断为只有接到数据后才会响应。在Arduino中,把要执行的查询放在loop下面反复执行就属于一种查询。但是查询具有一定缺点。在查询中计算机无法进行其他任务,只能等待数据,而中断使得计算机可以腾出内存进行其他任务,只有接受到数据在打断其他任务开始处理此事件。 例1:按钮中断 这是一个传统的查询实现按钮点灯 const int buttonPin = 2;

Raine_Yang的博客 9478

esp32外部中断_ESP32 Arduino教程:外部中断

简介此esp32 arduino教程旨在解释如何使用ESP32开发板和Arduino核心处理外部中断。测试是在一个集成在ESP32开发板中的DFRobot的ESP-WROOM-32设备上进行的。设置代码首先我们将对该中断附加在全局变量上的引脚进行声明。请注意,根据您的ESP32开发板,ESP32微控制器的引脚编号和开发板标注的引脚编号可能不匹配。在FireeBeetle esp32开发板中,以下使...

weixin_31706903的博客 3381

关于Arduino中的常用函数

一、I/O函数 二、时间函数 三、数学函数 abs 返回其参数的无符号值 【abs(12)返回12,abs(-12)也返回12】 constrain 限制一个数字以阻止它超出范围。第一个参数是被限制的数字,第二个参数是范围区间的开始,第三个参数是允许的数字范围区间的结尾。 【constrain(8,1,10)返回8,constrain(11,1,10)返回10,constrain(0,1,10)返回1】 map 将一个范围内的数字映射到另一个范围。第一个参数是要映射到数字,第二个和第三个参数是from范围(

TREE的博客 7323

ESP32 Arduino编程实例-定时器与中断 物联网

ESP32是一款功能强大的微控制器,结合Arduino编程语言,可以轻松地实现定时器和中断功能,为物联网项目提供精确的时间控制和事件处理。本文将介绍如何在ESP32上使用Arduino编程语言实现定时器和中断,并提供相应的源代码。通过合理使用定时器和中断,我们可以实现精确的时间控制和事件处理,为物联网项目提供更好的性能和功能。中断是一种特殊的事件,当某个条件满足时,会打断程序的正常执行,去处理这个事件。在物联网应用中,中断可以用于响应传感器的输入、处理外部设备的信号等。在上面的代码中,我们首先定义了一个。

XadxShapes的博客 727

【雕爷学编程】Arduino 手册之设置中断函数 attachInterrupt()

例如,如果要用一个按键控制一个LED的亮灭,可以用attachInterrupt()函数为按键引脚设置一个中断服务程序,当按键被按下或松开时,切换LED的状态。例如,如果要测量一个旋转编码器的转速,可以用attachInterrupt()函数为编码器引脚设置一个中断服务程序,当编码器每转动一步时,增加一个计数器的值。例如,如果要实现一个定时器功能,可以用attachInterrupt()函数为定时器引脚设置一个中断服务程序,当定时器每到达一定时间间隔时,执行一些任务。

雕爷学编程 1855

S7-1200模拟量

将两种不同的金属或合金金属焊接起来,构成一个闭合回路,利用温差电动势来测量温度,当两端存在温度梯度时,回路中就会有电流通过,此时两端之间就存在电动势--热电动势,这就是所谓的塞贝克效应(seebeck effect)。温差越大,热电动势越高。热电偶是有正负极性的,所以需要确保导线连接到正确的极性,否则会造成明显的测量误差。为了使温度补偿达到最佳效果,必须将热电偶模块安装在温度稳定的环境中简述:两种金属,每一种金属随温度变化是不同的,出现温差--由俩金属构成的回路就会有电流经过,因此两端形成热电动势。

王阿妹小天才的博客 2593

从动态规划到最优控制:Hamilton-Jacobi-Bellman (HJB) 方程的核心思想与应用

本文深入解析了Hamilton-Jacobi-Bellman (HJB) 方程的核心思想与应用,从动态规划到最优控制的演变过程。通过实际案例展示了HJB方程在机器人路径规划、工业机械臂优化等领域的实践价值,并探讨了数值求解方法和深度学习结合的神经HJB前沿进展。

weixin_28700411的博客 458

GB28181协议实战:5分钟搞定海康摄像头SIP注册失败问题(附Wireshark抓包分析)

本文详细解析了海康摄像头在GB28181协议下SIP注册失败的7个关键原因及解决方案,包括网络可达性、鉴权参数、NAT穿越等核心问题。通过Wireshark抓包分析,提供快速定位方法,帮助工程师高效解决SIP注册失败问题,提升实时图像联调效率。

weixin_29212867的博客 557

实战指南:如何用Kamailio+FreeSWITCH搭建高并发企业通信系统(附配置模板)

本文提供了一份实战指南,详细介绍了如何利用Kamailio与FreeSWITCH构建高并发企业通信系统。通过将Kamailio作为高性能SIP信令平面处理路由与负载均衡,FreeSWITCH作为媒体与应用平面负责通话与业务逻辑,实现信令与媒体分离的电信级架构。文章深入解析了架构设计、核心配置、集群部署与性能优化,并附有配置模板,旨在帮助企业构建可水平扩展、高可用的通信解决方案。

dell8的博客 364

ADS基础教程20 - 电磁仿真(EM)参数化仿真

一、引言二、参数化设置1.参数定义2.参数赋值3.创建EM模型和符号四、总结1)在Layout视图,菜单栏中选中EMComponent2)在弹出的参数编辑框中,采用标称/扰动()设计。使用子网(Subnetwork)参数。这些方法是互斥的,在为单个组件定义参数时不能将它们组合起来。标称/扰动(Nominal/Perturbed)参数使用平面化布局场景,并且只包含端口和原始图形形状(如多边形、矩形和圆形)时定义。

XZ_ZC的博客 4029

免费教你快速学会分析运算放大器电路(保证学会)

本文旨在学习如何快速简单地对运算放大器进行分析

一名热爱技术的工程师的博客。分享技术干货,记录美好生活。永远相信美好的事情即将发生。 1万+

【C语言】字符常量详解

字符常量是C语言中处理字符数据的重要工具。通过单引号括起一个字符,我们可以方便地使用字符常量进行字符判断、字符运算和字符串处理等操作。理解字符常量的表示方法、使用场景和ASCII码对应关系,对于编写高效的C语言程序至关重要。

LuckiBit 5020

二极管钳位电路、限幅电路和检波电路Multisim电路仿真

本文系统介绍了二极管钳位、限幅和检波三种基础电路的工作原理及Multisim仿真验证。钳位电路通过电容-二极管配合实现波形整体平移,将波峰或波谷固定在指定电压;限幅电路利用二极管导通特性削除信号超出设定阈值的部分;检波电路则通过半波整流和电容滤波从调幅波中提取音频信号。三种电路均通过Multisim仿真验证了理论分析结果,展示了二极管在信号处理中的关键作用。这些基础电路广泛应用于信号调理、电平保护和通信解调等领域。

XU157303764的博客 1125

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: MATLAB Simulink的Arduino支持包安装指南
下一篇: 使用Arduino实现蓝牙开关控制
普通网友
博客等级 码龄3年 90粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值