Hey guys, Im pretty new to programming so ill probably have a few questions along the way as I try to do this project. Just a quick explanation of what I am trying to do - Im programming an arduino to turn on and off a freezer relay during different times of the day. set the temp during the day 7am-7pm to -5 degrees and at night, 7pm - 7am to -20 degrees. I have the code keeping time, getting the temperature and light values and displaying them and am now trying to write the if/else statements that will jump to the two functions called Daytime and Nighttime. Here is the code:
#include <Wire.h>
#include "RTClib.h"
#define aref_voltage 3.3
RTC_DS1307 RTC;
int tempReading;
int tempPin = 1;
int photocellReading;
int photocellPin = 2;
void setup () {
Serial.begin(9600);
Wire.begin();
analogReference(EXTERNAL);
}
void loop () {
analogRead(photocellPin);
delay(10);
photocellReading = analogRead(photocellPin);
Serial.print("Light reading = ");
Serial.print(photocellReading); // the analog reading
// Thresholds for the photocell
if (photocellReading < 10) {
Serial.println(" - Dark");
} else if (photocellReading < 200) {
Serial.println(" - Dim");
} else if (photocellReading < 500) {
Serial.println(" - Light");
} else if (photocellReading < 800) {
Serial.println(" - Bright");
} else {
Serial.println(" - Very bright");
}
analogRead(tempPin);
delay(10);
tempReading = analogRead(tempPin);
Serial.print("Temp reading = ");
Serial.print(tempReading); // the analog reading
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage / 1024;
// print out the voltage
Serial.print(" - ");
Serial.print(voltage); Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");
// now convert to Fahrenheight
float temperatureF = (temperatureC * 9 / 5) + 32;
Serial.print(temperatureF); Serial.println(" degrees F");
DateTime now = RTC.now();
Serial.print("The time is:");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
delay(1000);
{
if (now.hour >= 7 && now.hour <= 19); //If time is between 7am and 7pm print day time setting)
{ //It will later call a function to check if the temp is between a value
Serial.print("Day time setting"); // and then turn a relay on for the freezer if not the correct setting
}
else // if it is not set to day time - set to night time. Which will call a function
{ // that turns on the freezer if not the correct "Night time" temp.
Serial.print("Night time setting");
}
}
}
My issue is with the last If/else statement. The line if (now.hour >= 7 && now.hour <= 19); is returning an error saying:
Complex_TempLight_Clock_pde:75: error: invalid use of member (did you forget the '&' ?)
Complex_TempLight_Clock_pde:79: error: 'else' without a previous 'if'.
Any help would be much appreciated.