byte ledPin = 8;
byte bntPin = 7;
boolean state;
boolean buttonUp;
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
pinMode(bntPin, INPUT);
digitalWrite(bntPin, HIGH);
}
void loop()
{
if(digitalRead(bntPin) == LOW && buttonUp == true)
{
state = !state;
digitalWrite(ledPin, state);
buttonUp = false;
}
else if(digitalRead(bntPin) == HIGH && buttonUp == false)
{
buttonUp = true;
}
delay(10); // Delay 時間可視情況調整
}
沒有留言:
張貼留言