I'm having some problems to write my code for a very simple project:
I'm doing a feeder for my chicken and I want to have to make a an action if some conditions are archived. However I'm having the folowing error: 'invalid use of member function (did you forget the '()'?)'
Can anyone help to solve this?
Thanks
if (rtc.month >= 4 && rtc.month <= 9 && rtc.second == 0 && rtc.minute == 0);
{
if (rtc.hour == 8 || rtc.hour == 12 || rtc.hour == 16 || rtc.hour == 19);
{
digitalWrite(OUTPUT_PIN,HIGH); // Sets the digital pin on
}
}
else if (rtc.month < 4 && rtc.month > 9 && rtc.second == 0 && rtc.minute == 0);
{
if (rtc.hour == 8 || rtc.hour == 12 || rtc.hour == 16);
{
digitalWrite(OUTPUT_PIN,HIGH); // Sets the digital pin on
}
}
I want to set a schedule to feed my chickens (at this point is just to light a LED but I will add a servo later).
I want the following schedule:
Summer time (April to September): feed every day at 8h00, 12h00, 16h00 and 19h00
Winter time (October to March): feed every day at 8h00, 12h00 and 16h00
I'm using a RTC DS1307 and the libraries SparkFunDS1307RTC.h and Wire.h.
You pointed out multiple times, but I didn't understand what you mean...
Now is working but I don't understand why the arduino always runs if (mo < 4 && mo > 9 && s == 0 && m == 0);
Here is my code (it's a little messy but I'm working on it):
#include <SparkFunDS1307RTC.h> //DS1307 libray
#include <Wire.h> //Wire library allows communicate with I2C/WI devices
// Constants
const int OUTPUT_PIN = 2; // Output pin 2
// Variables
void setup() {
// put your setup code here, to run once:
// Use the serial monitor to view time/date output
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(OUTPUT_PIN, OUTPUT); //Sets the digital pin as output
rtc.begin(); // Call rtc.begin() to initialize the library
// Now set the time...
// You can use the autoTime() function to set the RTC's clock and
// date to the compiliers predefined time. (It'll be a few seconds
// behind, but close!)
// rtc.autoTime(); //Consider commenting out the autoTime or setTime entirely once you've perfectly configured the clock
// Or you can use the rtc.setTime(s, m, h, day, date, month, year)
// function to explicitly set the time:
// e.g. 18:59:30 | Saturday August 18, 2018:
rtc.setTime(30, 59, 18, 7, 18, 8, 18); // Uncomment to manually set time
// rtc.set12Hour(); // Use rtc.set12Hour to set to 12-hour mode
}
void loop() {
// put your main code here, to run repeatedly:
// Call rtc.update() to update all rtc.seconds(), rtc.minutes(),
// etc. return functions.
rtc.update();
static int8_t lastSecond = -1;
if (rtc.second() != lastSecond) // If the second has changed
{
Serial.print(String(rtc.hour()) + ":"); // Print hour
if (rtc.minute() < 10)
Serial.print('0'); // Print leading '0' for minute
Serial.print(String(rtc.minute()) + ":"); // Print minute
if (rtc.second() < 10)
Serial.print('0'); // Print leading '0' for second
Serial.print(String(rtc.second())); // Print second
if (rtc.is12Hour()) // If we're in 12-hour mode
{
// Use rtc.pm() to read the AM/PM state of the hour
if (rtc.pm()) Serial.print(" PM"); // Returns true if PM
else Serial.print(" AM");
}
Serial.print(" | ");
// Few options for printing the day, pick one:
Serial.print(rtc.dayStr()); // Print day string
//Serial.print(rtc.dayC()); // Print day character
//Serial.print(rtc.day()); // Print day integer (1-7, Sun-Sat)
Serial.print(" - ");
#ifdef PRINT_USA_DATE
Serial.print(String(rtc.month()) + "/" + // Print month
String(rtc.date()) + "/"); // Print date
#else
Serial.print(String(rtc.date()) + "/" + // (or) print date
String(rtc.month()) + "/"); // Print month
#endif
Serial.println(String(rtc.year())); // Print year
lastSecond = rtc.second(); // Update lastSecond value
}
// Read the time:
int s = rtc.second();
int m = rtc.minute();
int h = rtc.hour();
// Read the day/date:
int dy = rtc.day(); // “Day” is as in “day of the week”, e.g. Sunday, Monday, Tuesday… rtc.day() returns an integer between 1 and 7, where 1 is Sunday and 7 is Saturday.Alternatively, you can call rtc.dayChar() or rtc.dayStr(), which return a character or full-string representation of the day of the week.
int da = rtc.date();
int mo = rtc.month();
int yr = rtc.year();
if (mo >= 4 && mo <= 9 && s == 0 && m == 0)
{
if (h == 8 || h == 12 || h == 16 || h == 19);
{
//digitalWrite(OUTPUT_PIN,HIGH); // Sets the digital pin on
}
}
if (mo < 4 && mo > 9 && s == 0 && m == 0);
{
if (h == 8 || h == 12 || h == 16);
{
digitalWrite(OUTPUT_PIN,HIGH); // Sets the digital pin on
}
}
}