int ledpin = 12; //led输出 int inpin = 7; //按键输入 int val; //全局变量 int x = 0; //全局变量 void setup() { pinMode(ledpin,OUTPUT); pinMode(inpin,INPUT); } void loop() { val = digitalRead(inpin); //读取按键输入量 if(val == HIGH){ //如果按下 delay(1500); //延1.5S val = digitalRead(inpin); if(val == HIGH){ //如果任为按下 while(x == 0){ //长1.5 led灯闪烁 digitalWrite(ledpin,HIGH); delay(500); digitalWrite(ledpin,LOW); delay(500); val = digitalRead(inpin); if(val == HIGH){ x=1; break; //跳出循环 } } } else if (x == 0){ digitalWrite(ledpin,HIGH); x = 1; delay(500); } else if (x == 1){ digitalWrite(ledpin,LOW); x = 0; delay(500); } } }