Millis greater that 5 minutes Alternatives


i'm still fumbling through learning c++ , arduino.  have mega 8 channel relay.  below code part of larger project.  have rtc ds3231 working purpose.  below snippet of code controlling pump (45 minutes on , 15 minutes off each hour).  did not realize there limitation millis.  works 1 minute on , 5 off @ moment.  did search forums , found 12 different ways expert opinion before going off in wrong direction.  guidance appreciated.  need multitask other ops delay() wont work. current pump prog code:

//pump program v 1.0

//**********declaration*****************************
const byte pump_relay =  8;                       // pump relay pin 8
int pump_state = low;                         
unsigned long pump_previousmillis = 0;            // track last time pump ran
unsigned long pump_on_sp = 1000;               // sp how long pump running; 45 minutes = 2700000
unsigned long pump_off_sp = 10000;               // sp how long pump off; 15 minutes = 900000
int pump_interval = pump_off_sp;                  // how long dwell pump off time
boolean pump_relay_8_state = true;                // tracks if pump should on/off

void setup() {
  pinmode(pump_relay, output);
}

void loop() {
                                                 // set pin pump_relay state of pump_relay_8_state each timethrough loop()
                                                 // if pump_relay_8_state hasn't changed, neither pin
  digitalwrite(pump_relay, pump_relay_8_state);

  unsigned long currentmillis = millis();         // pull current time
                                                  // compare previous capture see if enough time has passed
  if ((unsigned long)(currentmillis - pump_previousmillis) >= pump_interval) {
                                                  // change wait pump_interval, based on current led state
    if (pump_relay_8_state) {                       
      pump_interval = pump_on_sp;                 // pump on, set time stay off
    } else {
      pump_interval = pump_off_sp;                // pump off, set time stay on
    }
    pump_relay_8_state = !(pump_relay_8_state);   // toggle pump_relay_8_state
    pump_previousmillis = currentmillis;          // save current time compare "next"
  }
}

you use millis same way 5 minutes 1 minute.  there's no problem millis until interval times larger 49 days. 


Arduino Forum > Using Arduino > Programming Questions > Millis greater that 5 minutes Alternatives


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts