运行多少秒 就停止 除非重新上电 arduino uno
1 #include <EEPROM.h> 2 int led=2; 3 int jia=3; 4 int jian=4; 5 6 int temp=0; 7 int t=22;//设定的秒 8 int t_t=0; 9 int addr = 1;//保存数据的地址 10 11 void panduan(void); 12 void pd_io(void); 13 //void pd_baocun(addr,t,t_t); 14 15 void setup() { 16 pinMode(jia, INPUT_PULLUP); 17 pinMode(jian, INPUT_PULLUP); 18 pinMode(led, OUTPUT); 19 temp=millis()/1000; 20 t_t=EEPROM.read(addr); 21 if(t_t<250 || t_t>1) 22 {t=t_t;} 23 else 24 t_t=t; 25 } 26 27 void loop() 28 { 29 //pd_baocun(addr,t,t_t); 30 31 if(millis()/1000 >(t-2) ) 32 { 33 34 if(t_t!=t){ EEPROM.write(addr,t);} 35 } 36 panduan(); 37 pd_io(); 38 } 39 40 41 42 void pd_io(void) 43 { 44 if(digitalRead(jia)==LOW) 45 { 46 delay(15); 47 if(digitalRead(jia)==LOW) 48 { 49 t++; 50 51 } 52 } 53 if(digitalRead(jian)==LOW) 54 { 55 delay(15); 56 if(digitalRead(jian)==LOW) 57 { 58 t--; 59 60 } 61 } 62 63 } 64 65 66 void panduan(void) 67 { 68 69 if(millis()/1000 >t) 70 { 71 digitalWrite(led, HIGH); 72 } 73 else 74 digitalWrite(led, LOW); 75 }