- int btnPin=2;
- int ledPin=13;
- bool btnStatus;
- int startTime;
- void setup()
- {
- Serial.begin(9600);
- pinMode(btnPin,INPUT);
- pinMode(ledPin,OUTPUT);
- startTime=millis();
- }
- void loop()
- {
- btnStatus=digitalRead(btnPin);
-
- //Serial.println(millis());
-
- if(millis()-startTime<=10000)
- digitalWrite(ledPin,HIGH);
- else
- digitalWrite(ledPin,LOW);
- if(btnStatus==true)
- startTime-=10000;
- delay(50);
- }
複製代碼 |