×

按钮检查器开源分享

消耗积分:0 | 格式:zip | 大小:0.43 MB | 2022-11-14

李华瑞

分享资料个

描述

使用此项目了解更多关于您的按钮的信息!

编码:

#define buttonPin 2
#define ledPin 13
bool state = 0;
bool lastRead = 0;
void setup() {
 // put your setup code here, to run once:
Serial.begin(9600);
pinMode(2,INPUT);
pinMode(13,OUTPUT);
}
void loop() {
 // put your main code here, to run repeatedly:
state = digitalRead(2);
if(state != lastRead)
{
 Serial.println(state);
digitalWrite(ledPin,state)
 lastRead = state;
}
}

----------------------------------

#define buttonPin 2 

将单词“buttonPin”定义为数字 2,所以当你写“buttonPin”时 = 当你写 2

#define ledPin 13

将单词“ledPin”定义为数字 13 所以当你写“ledPin”时 = 当你写 13

bool state = 0; 

按钮的状态

bool lastRead = 0; 

按钮的最后读数

void setup() {
 // put your setup code here, to run once:
Serial.begin(9600);
pinMode(buttonPin,INPUT); 
}

 

Serial.begin(9600);

定义串行监视器

pinMode(buttonPin,INPUT); 

定义“buttonPin”模式

void loop() {
 // put your main code here, to run repeatedly:
state = digitalRead(2);
if(state != lastRead)
{
 Serial.println(state);
digitalWrite(ledPin,state)
 lastRead = state;
}
}

 

state = digitalRead(2);

将按钮的读数置于“状态”

if(state != lastRead)

如果“状态”不是“lastReading”

Serial.println(state);

将“状态”打印到串行监视器中

digitalWrite(ledPin,state)

将按钮的状态写入引脚 13

lastRead = state;

使“lastRead”=“状态”值


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !