I did a timer, but there is a inconveninet. When one wants to turn on the system,
the pump starts only after "soakInterval" time or "soakInterval + soakON" time.
depending on "int state = LOW;" or "int state = HIGH", respectively.
is there any way of pump starting right after the loop begin?
int state = LOW;
unsigned long previousMillis = 0;
unsigned long currentMillis;
int soakON = 10000;
unsigned long soakInterval = 20000;
int solenoid = 3;
int pump = 5;
int lag = 2000;
void setup(){
Serial.begin(9600);
pinMode(solenoid, OUTPUT);
pinMode(pump, OUTPUT);
}
void loop(){
currentMillis = millis();
if(state == LOW && currentMillis - previousMillis >= soakInterval){
previousMillis = currentMillis;
state = HIGH;
digitalWrite(solenoid, state);
digitalWrite(pump, state);
}
if(state == HIGH && currentMillis - previousMillis >= soakON){
previousMillis = currentMillis;
state = LOW;
digitalWrite(pump, state);
delay(lag);
digitalWrite(solenoid, state);
}
is there any way of pump starting right after the loop begin?
Why not turn it on in setup() ?
Why not turn it on in setup() ?
I think I made an incomplete question trying to cut the code above that.
currentMillis = millis();
DateTime now = RTC.now();
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.print(" ");
minSinceMid = 60*now.hour() + now.minute();
Serial.print("Min = ");
Serial.print(minSinceMid);
Serial.println(" ");
if( minSinceMid >= interval_a && minSinceMid < interval_b || minSinceMid >= interval_c && minSinceMid < interval_d || minSinceMid >= interval_e && minSinceMid < interval_f ){
if(state == LOW && currentMillis - previousMillis >= soakInterval){
previousMillis = currentMillis;
state = HIGH;
digitalWrite(solenoid, state);
digitalWrite(pump, state);
}
if(state == HIGH && currentMillis - previousMillis >= soakON){
previousMillis = currentMillis;
state = LOW;
digitalWrite(pump, state);
delay(lag);
digitalWrite(solenoid, state);
}
}
The sketch reads time and it compares if it fits inside any of these 3 time intervals. If true, then turn on the pump right after. But I don´t know how to turn up the pump for the first time without any interval.
I am sorry, but I don't understand the question. If you want to
turn up the pump for the first time without any interval.
then why not do it in setup() ?