byte led1Pin = 8;
byte led2Pin = 9;
byte bnt1Pin = 2;
byte bnt2Pin = 3;
boolean state1;
boolean state2;
boolean buttonUp1;
boolean buttonUp2;
void setup()
{
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, HIGH);
pinMode(bnt1Pin, INPUT);
pinMode(bnt2Pin, INPUT);
digitalWrite(bnt1Pin, HIGH);
digitalWrite(bnt2Pin, HIGH);
}
void loop()
{
if(digitalRead(bnt1Pin) == LOW && buttonUp1 == true)
{
state1 = !state1;
digitalWrite(led1Pin, state1);
buttonUp1 = false;
}
else if(digitalRead(bnt1Pin) == HIGH && buttonUp1 == false)
{
buttonUp1 = true;
}
if(digitalRead(bnt2Pin) == LOW && buttonUp2 == true)
{
state2 = !state2;
digitalWrite(led2Pin, state2);
buttonUp2 = false;
}
else if(digitalRead(bnt2Pin) == HIGH && buttonUp2 == false)
{
buttonUp2 = true;
}
delay(10); // Delay 時間可視情況調整
}
沒有留言:
張貼留言