Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. void loop(){
  2.   if (f_wdt==1) {  // wait for timed out watchdog / flag is set when a watchdog timeout occurs
  3.     if(circles <= count){
  4.       //Count reached, lets start our MOSFET
  5.      
  6.       //Start with Setup our PINS and the millis to compare
  7.       if(f_start==0){
  8.         pinMode(pinGate,OUTPUT); //Set Gate as Output
  9.         pinMode(readGate,INPUT_PULLUP); //Set Read Gate to Pullup will LOW when closed and HIGH when open
  10.         unsigned long startMillis = millis(); //Snapshot of current time
  11.         digitalWrite(pinGate, HIGH); //Output High to MOSFET to open the gate
  12.         f_start = 1; //set setup flag as finished
  13.       }
  14.  
  15.       //Setup is finished, lets see if we should stop open the MOSFET
  16.       if(f_start==1){
  17.         if(digitalRead(readGate) == LOW) f_done = 1; //We got a signal, lets start new sleep circle
  18.         unsigned long currentMillis = millis(); //Our current Millis
  19.         if ((unsigned long)(currentMillis - startMillis) >= waitTime) f_done = 1;  //Timeout time is reached, lets start new sleep circle
  20.       }
  21.      
  22.       if(f_done==1){
  23.         digitalWrite(pinGate, LOW);
  24.         // set all used port to intput to save power
  25.         pinMode(pinGate,INPUT);
  26.         pinMode(readGate,INPUT);
  27.         f_start = 0;    // reset setup flag
  28.         f_done = 0;     // reset open circle flag
  29.         count = 0;      // reset sleep cycle count
  30.         f_wdt=0;       // reset watchdog flag
  31.         system_sleep(); // back to sleep little tiny
  32.       }
  33.     } else {
  34.       //Count has not reached Circles yet, just go back to sleep and count up
  35.       count++;
  36.       f_wdt=0;       // reset watchdog flag
  37.       system_sleep(); // back to sleep little tiny
  38.     }
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement