Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loop(){
- if (f_wdt==1) { // wait for timed out watchdog / flag is set when a watchdog timeout occurs
- if(circles <= count){
- //Count reached, lets start our MOSFET
- //Start with Setup our PINS and the millis to compare
- if(f_start==0){
- pinMode(pinGate,OUTPUT); //Set Gate as Output
- pinMode(readGate,INPUT_PULLUP); //Set Read Gate to Pullup will LOW when closed and HIGH when open
- unsigned long startMillis = millis(); //Snapshot of current time
- digitalWrite(pinGate, HIGH); //Output High to MOSFET to open the gate
- f_start = 1; //set setup flag as finished
- }
- //Setup is finished, lets see if we should stop open the MOSFET
- if(f_start==1){
- if(digitalRead(readGate) == LOW) f_done = 1; //We got a signal, lets start new sleep circle
- unsigned long currentMillis = millis(); //Our current Millis
- if ((unsigned long)(currentMillis - startMillis) >= waitTime) f_done = 1; //Timeout time is reached, lets start new sleep circle
- }
- if(f_done==1){
- digitalWrite(pinGate, LOW);
- // set all used port to intput to save power
- pinMode(pinGate,INPUT);
- pinMode(readGate,INPUT);
- f_start = 0; // reset setup flag
- f_done = 0; // reset open circle flag
- count = 0; // reset sleep cycle count
- f_wdt=0; // reset watchdog flag
- system_sleep(); // back to sleep little tiny
- }
- } else {
- //Count has not reached Circles yet, just go back to sleep and count up
- count++;
- f_wdt=0; // reset watchdog flag
- system_sleep(); // back to sleep little tiny
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement