Here's the second part:
/* ******************************************************************************************************************** */
/* * * */
/* * S E T U P * */
/* * * */
/* ******************************************************************************************************************** */
void setup() {
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH);
pinMode(ledPin, OUTPUT); // Set our LED as an output pin
//pinMode(ledPin1, OUTPUT); // set the digital pin as output:
// pinMode(ledPin2, OUTPUT);
pinMode (heater, OUTPUT);
pinMode(moon, OUTPUT); // Set analog pin 1 as a output
sensors.begin();
/* ******************************************************************************************************************** */
/* * * */
/* * S E T U P - D I S P L A Y * */
/* * * */
/* ******************************************************************************************************************** */
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
second = 10;
minute = 59;
hour = 11;
dayOfWeek = 6; // Sunday is 0
dayOfMonth = 26;
month = 2;
year = 11;
//Use the next line for setting the clock
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
lcd.begin(20, 4); // set up the LCD's number of rows and columns:
lcd.setCursor(0, 3);
lcd.print("Moon:");
lcd.setCursor(0, 1);
lcd.print("Lights:");
lcd.setCursor(0, 2);
lcd.print("Heater:");
digitalWrite(ledPin, LOW); // Set the LED to LOW (off)
Wire.begin(); // Start our wire and real time clock
RTC.begin();
if (! RTC.isrunning()) { // Make sure RTC is running
// Serial.println("RTC is NOT running!");
// RTC.adjust(DateTime(03__DATE_21_, _5_TIME47__)); // Uncomment to set the date and time
}
}
void loop () {
sensors.requestTemperatures(); // Send the command to get temperatures
lcd.setCursor(12, 0);
lcd.print(sensors.getTempFByIndex(0));
lcd.print((char)223);
if (sensors.getTempFByIndex(0) < heater_on_temp) HeaterOn();
if (sensors.getTempFByIndex(0) > heater_off_temp) HeaterOff();
lcd.setCursor(14, 2);
delay(1000);
DateTime now = RTC.now(); // Read in what our current datestamp is from RTC
if (now.second() == 0) { // Only process if we have ticked over to new minute
if (poweredOn == 0) { // Check if lights currently powered on
checkStartTime(); // If they are not, check if it's time to turn them on
}
else {
checkEndTime(); // Otherwise, check if it's time to turn them off
}
if (validStart == 1) { // If our timer is flagged to start, turn the lights on
turnLightsOn();
lcd.setCursor(9, 1);
lcd.print("ON ");
MoonOff();
}
if (validEnd == 1) { // If our time is flagged to end, turn the lights off
turnLightsOff();
lcd.setCursor(9, 1);
lcd.print("OFF ");
MoonOn();
}
}
delay(1000);
}
byte checkStartTime() {
DateTime now = RTC.now(); // Read in what our current datestamp is from RTC
if (now.hour() == startHour && now.minute() == startMinute) {
validStart = 1; // If our start hour and minute match the current time, set 'on' flags
poweredOn = 1;
}
else {
validStart = 0; // Otherwise we don't need to power up the lights yet
}
return validStart; // Return the status for powering up
}
byte checkEndTime() {
DateTime now = RTC.now(); // Read in what our current datestamp is from RTC
if (now.hour() == endHour && now.minute() == endMinute) {
validEnd = 1; // If our end hour and minute match the current time, set the 'off' flags
poweredOn = 0;
}
else {
validEnd = 0; // Otherwise we don't need to power off the lights yet
}
return validEnd; // Return the status for powering off
}
void turnLightsOn() {
digitalWrite(ledPin, HIGH); // Turn on the LED
}
void turnLightsOff()
{
digitalWrite(ledPin, LOW); // Turn off the LED
{
// onesecond(); // updates clock once per second
// countdown--;
}
}