本站改版新增arduino频道
arduino 外部中断0、外部中断1
bool rstate = false; //外部中断0,控制输出
bool bstate = false; //外部中断1,控制输出
void setup()
{
Serial.begin(9600);
attachInterrupt(0,RStateChange,FALLING); //外部中断0,对应输入的引脚2。下降沿触发。对应中断函数:StateChange()
attachInterrupt(1,BStateChange,FALLING); //外部中断1,对应输入的引脚3。下降沿触发。对应中断函数:BStateChange()
pinMode(5,OUTPUT);
pinMode(7,OUTPUT);
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
}
void loop()
{
digitalWrite(5,rstate);
digitalWrite(7,bstate);
}
//外部中断0函数
void RStateChange()
{
rstate = !rstate;
bstate = false;
}
//外部中断1函数
void BStateChange()
{
bstate = !bstate;
rstate = false;
}
Copyright © 2014 ESP56.com All Rights Reserved
晋ICP备14006235号-22 晋公网安备14108102001165号
执行时间: 0.0091700553894043 seconds