int led = 10;
int sw1 = 3;
int value=0;
int ledState=LOW;
int debounceDelay=20;
void setup()
{
// put your setup code here, to run once:
pinMode(led,OUTPUT);
pinMode(sw1,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
value=digitalRead(sw1);
if(value==0)
{
delay(debounceDelay);
while(digitalRead(sw1)==LOW)
;
ledState=!ledState;
digitalWrite(led,ledState);
}
}
沒有留言:
張貼留言