k so i updated my code, with the arrays, and saved alot of bytes actually,
i appreciate that. i also learnt a bit more about variables, now im starting to get this a bit,
i also understand 0 counts as a number with coding,
so now that its updated
if i was to inject odometers suggestion with the way to do it, ,
how would i add a digitalWrite (circpump,HIGH); to that?
and it would go in the "water void" or "circ void"
im assuming it would just be a sub section in the water void becuase its pulling variables from the array?
#include "RTClib.h"
#include <Wire.h>
#include <LiquidCrystal.h>
DS3231 rtc;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Pins /////////////////////////////////////////////
//water pump relay pin
#define waterpump 5
//Light 1 pin
#define light1 3
//Light 2 pin
#define light2 4
#define circ 2
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Misc /////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Water ///////////////////////////////////////
//amount of time water is on for; watering length
const int watertime = 17000;
////////////////////////////////////////////////////////////////////////////////////////////////////////lights/////////////////////////////////////
//Light 1
//on
const int light1OnHour = 12;
const int light1OnMinute = 1;
//off
const int light1OffHour = 0;
const int light1OffMinute = 1;
//Light 2
//on
const int light2OnHour = 12;
const int light2OnMinute = 6;
//off
const int light2OffHour = 0;
const int light2OffMinute = 6;
//////////////////////////////////////////////////////////////// other shit waiting to give me a headache///////////////////////////////////////////////////////////////////
/*Relay4
const int OnHour = ;
const int OnMinute = ;
const int OnSecond = ;
const int OffHour = ;
const int OffMinute = ;
const int OffSecond = ;
//Relay5
const int OnHour = ;
const int OnMinute = ;
const int OnSecond = ;
const int OffHour = ;
const int OffMinute = ;
const int OffSecond = ;
//Relay6
const int OnHour = ;
const int OnMinute = ;
const int OnSecond = ;
const int OffHour = ;
const int OffMinute = ;
const int OffSecond = ;
//Relay7
const int OnHour = ;
const int OnMinute = ;
const int OnSecond = ;
const int OffHour = ;
const int OffMinute = ;
const int OffSecond = ;
//Relay8
const int OnHour = ;
const int OnMinute = ;
const int OnSecond = ;
const int OffHour = ;
const int OffMinute = ;
const int OffSecond = ;
*/
void setup() {
Serial.begin(9600);
Wire.begin();
rtc.begin();
rtc.adjust(DateTime(__DATE__, __TIME__));
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
//set pins (outputs)
pinMode(waterpump, OUTPUT);
pinMode(light1, OUTPUT);
pinMode(light2, OUTPUT);
pinMode(circ, OUTPUT);
//set pins (inputs)
}
void loop() {
printtime();
water();
lights();
circulation();
}
void printtime()
{
// serial print out of time
DateTime now = rtc.now();
char buf[100];
strncpy(buf, "DD.MM.YYYY hh:mm:ss\0", 100);
Serial.println(now.format(buf));
}
void water()
{
DateTime now = rtc.now();
static unsigned long wateron = 0;
///// number of pump on times
const int NUM_PUMP_ON_TIMES = 4;
//// times the pumps turn on (HH:MM:SS)
const int pumpOnTime[NUM_PUMP_ON_TIMES][3] = {{14, 58, 1}, {14, 59, 1}, {15, 0, 1}, {15, 1, 1}};
for (int i = 0; i < NUM_PUMP_ON_TIMES; i++) {
// remember, array indices start from 0
if (now.hour() == pumpOnTime[i][0] && now.minute() == pumpOnTime[i][1] && now.second() == pumpOnTime[i][2])
{
Serial.println("water pump is on");
digitalWrite(waterpump, HIGH);
wateron = millis();
}
}
if (digitalRead(waterpump) == HIGH)
{
if (millis() - wateron > watertime)
{
digitalWrite(waterpump, LOW);
Serial.println("water pump is off");
}
}
}
void lights()
{
DateTime now = rtc.now();
/////light 1//////////////
if (now.hour() == light1OnHour && now.minute() == light1OnMinute)
{ Serial.println("light 1 is on");
digitalWrite(light1, HIGH);
}
if (now.hour() == light1OffHour && now.minute() == light1OffMinute)
{ Serial.println("light 1 is off");
digitalWrite(light1, LOW);
}
////////////light2///////////
if (now.hour() == light2OnHour && now.minute() == light2OnMinute)
{ Serial.println("light 2 is on");
digitalWrite(light2, HIGH);
}
if (now.hour() == light2OffHour && now.minute() == light2OffMinute)
{ Serial.println("light 2 is off");
digitalWrite(light2, LOW);
}
}
void circulation()
{
}