int led = 3;
int button = 2;
void setup() {
// put your setup code here, to run once:
pinMode(led,OUTPUT);
pinMode(button,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
//点击亮灯,再点熄灯
while(1){
if(digitalRead(button) == LOW){
delay(150);
if(digitalRead(button) == LOW){
digitalWrite(led,!digitalRead(led));
}
}
//点击亮灯,松手熄灯
// while(1){
// if(digitalRead(button) == LOW){
// digitalWrite(led,HIGH);
// }else{
// digitalWrite(led,LOW);
// }
}
}


网友评论