1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
int btnStart=4; unsigned long cnt=5000; unsigned long times=0; int states=0; void setup() { Serial.begin(9600); pinMode(btnStart, INPUT); } void loop() { if (digitalRead(btnStart) && states==0) { states=1; times=millis(); } if (states==1) { if (millis()-times > cnt) { states=0; Serial.println("Alarm"); } else { Serial.println( (cnt-(millis()-times))/1000.0 ); } } } |