利用讀取GPIO做投票機功能
按下按鍵,對應LED亮起
注意按鍵跟LED都要經過電阻接地
//投票機
int YesLed=10;
int NoLed=9;
int YesPin=7;
int NoPin=6;
int Yes;
int No;
void setup() {
// put your setup code here, to run once:
pinMode(YesLed,OUTPUT);
pinMode(NoLed,OUTPUT);
pinMode(YesPin,INPUT);
pinMode(NoPin,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Yes = digitalRead(YesPin);
if(Yes == LOW)
{
digitalWrite(YesLed,LOW);
}else{
digitalWrite(YesLed,HIGH);
}
No = digitalRead(NoPin);
if(No == LOW)
{
digitalWrite(NoLed,LOW);
}else{
digitalWrite(NoLed,HIGH);
}
}
沒有留言:
張貼留言