boolean state = false;
boolean btn_up = true;
void setup()
{
pinMode(2, INPUT);
// digitalWrite(3,HIGH);
pinMode(3, OUTPUT);
digitalWrite(3, state);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(2) == LOW && btn_up == true)
{
state = !state;
digitalWrite(3, state);
btn_up = false;//你壓下去是false
}
else if (digitalRead(2) == HIGH && btn_up == false)//放開 且 btn_false
{
Serial.println("else if");
Serial.println(btn_up);
btn_up = true;
Serial.println(btn_up);
}
Serial.println("loop");
Serial.println(btn_up);
delay(1000);
}
沒有留言:
張貼留言