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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
int btnStart=4; int btnReset=5; unsigned long cnt=1000; unsigned long times=0; unsigned long cnt2=0; int states=0; void setup() { Serial.begin(9600); pinMode(btnStart, INPUT); pinMode(btnReset, INPUT); } void loop() { if (digitalRead(btnStart) && states==0 && cnt2==0) { states=1; times=millis(); //Serial.print("times : "); //Serial.println(times); cnt2=millis(); } else if (digitalRead(btnReset) && states==0 && cnt2==0) { cnt+=1000; if (cnt > 10000) { cnt=1000; } Serial.print("Set : "); Serial.print(cnt/1000); Serial.println("s"); cnt2=millis(); } else if (digitalRead(btnReset) && states==1 && cnt2==0) { states=0; Serial.println("Stop!!"); cnt2=millis(); } else if (millis() > cnt2+200) { cnt2=0; } if (states==1) { if (millis()-times > cnt) { states=0; Serial.println("Alarm"); } else { Serial.println( ( cnt-(millis()-times))/1000.0 ); } } } |