I am new to Arduino development. I want to use millis function instead delay because delay is blocking further execution of program.
Programme description: In this code i want to control 2 solenoid valves with ds3231 RTc alarm and also with infrared remote control button pressed.
But when i press one button for valve ON progam does not turn valve on.
plz check this program and correct my mistake.
#include <DS3231.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include "IRremote.h"
#define LED1 2
int receiver=6;
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
#define VALVE1 7
#define VALVE2 12
DS3231 rtc(SDA, SCL);
Time t;
//-------------millis timer----------------------------------
unsigned long last1 = millis();
void setup()
{
irrecv.enableIRIn(); // Start the receiver
rtc.begin();
Serial.begin(9600);
pinMode(VALVE1,OUTPUT);
pinMode(VALVE2,OUTPUT);
}
void loop()
{ t = rtc.getTime(); // Get data from the DS3231
delay(200);
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value
}
//------ALARM FOR AUTO WATERING GARDEN----
//MORNING Routine FOR VALVE========
if (t.hour == 16 && t.min == 15 && t.sec == 00) //Open valve1 8AM morning
{void G_valve1On();}
if (t.hour == 16 && t.min == 20 && t.sec == 00) //close valve1 8:10AM morning
{void G_valve1Off();}
//---------FUNCTIONS-----------------------------
//IR COMMAND FUNCTIONS
void translateIR()
{
switch(results.value)
{
case 0x843509F6: //valve 1 turn on for 10minute delay
if (millis() - last1 >600000) //when remote button pressed valve turn on for 10min
{ G_valve1On();
Serial.println("valve ON");
}
G_valve1Off();
Serial.println("valve off");
delay(250);
break;
case 0x84350AF5: //2nd button for 15 min delay
G_valve2On();
//Serial.println("valve on 15minutes...");
//Help me to use MILLS FUNCTION.
G_valve2Off();
//Serial.println("valve off");
delay(250);
break;
}
delay(300);
}
//----VALVES- FUNCTION------
void G_valve1On()
{
digitalWrite(VALVE1,HIGH);
Serial.println("...turning valve1 on...");
}
void G_valve1Off()
{
digitalWrite(VALVE1,LOW);
Serial.println("...turningvalve1 off...");
}
void G_valve2On()
{
digitalWrite(VALVE2,HIGH);
Serial.println("...turning valve1 on...");
}
void G_valve2Off()
{
digitalWrite(VALVE2,LOW);
Serial.println("...turningvalve1 off...");
}