Hello! I hate to resort to this, as I'm sure it's an easy fix I'm simply overlooking, but I've scoured for a solution to this for a week now, and from my meager understanding of functions, it seems as though the function has no frame of reference for 'getDate'. I'm setting up a basic controller for a water pump, but wanted to be able to display time, referencing an RTC from the date/time it was compiled(more for aesthetics at this point)
I'm using a DS1307 and using the DS1307RTC.h library.
When I run the example library SetTime.ino -- I receive no errors -- everything compiles just fine. Leading me to believe its not anything with the library.
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
tmElements_t tm;
void setup() {
bool parse=false;
bool config=false;
// get the date and time the compiler was run
if (getDate(__DATE__) && getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(200);
if (parse && config) {
Serial.print("DS1307 configured Time=");
Serial.print(__TIME__);
Serial.print(", Date=");
Serial.println(__DATE__);
} else if (parse) {
Serial.println("DS1307 Communication Error :-{");
Serial.println("Please check your circuitry");
} else {
Serial.print("Could not parse info from the compiler, Time=\"");
Serial.print(__TIME__);
Serial.print("\", Date=\"");
Serial.print(__DATE__);
Serial.println("\"");
}
}
void loop() {
}
bool getTime(const char *str)
{
int Hour, Min, Sec;
if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}
bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;
if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++) {
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}
However when I try and implement this into my own project(Irrigation_controller_7) *yes another one of those), something gets lost in the transition or is being muddied up from what little code I've already placed in here. I keep getting this "'getDate' was not declared in this scope" return
pointing me to this >> if (getDate(DATE) && getTime(TIME)) {
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <TimeLib.h>
#include <LCD.h>
#include <DS1307RTC.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
tmElements_t tm;
int Relay_3 = 11;
int Relay_5 = 8;
int Relay_6 = 9;
int Relay_8 = 13;
void setup() {
bool parse=false;
bool config=false;
// get the date and time the compiler was run
if (getDate(__DATE__) && getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(200);
if (parse && config) {
Serial.print("DS1307 configured Time=");
Serial.print(__TIME__);
Serial.print(", Date=");
Serial.println(__DATE__);
} else if (parse) {
Serial.println("DS1307 Communication Error :-{");
Serial.println("Please check your circuitry");
} else {
Serial.print("Could not parse info from the compiler, Time=\"");
Serial.print(__TIME__);
Serial.print("\", Date=\"");
Serial.print(__DATE__);
Serial.println("\"");
}
}
lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("Welcome to:");
lcd.setCursor(0, 1);
lcd.print("Garduino - v1.0");
delay(3000);
lcd.clear();
lcd.print(" BY EDGEWOOD ");
lcd.setCursor(0,1);
lcd.print("~~~~~~~~~~~~~~~~");
delay(2000);
lcd.clear();
pinMode(Relay_3, OUTPUT);
pinMode(Relay_5, OUTPUT);
pinMode(Relay_6, OUTPUT);
pinMode(Relay_8, OUTPUT);
pinMode(Relay_3, LOW);
pinMode(Relay_5, LOW);
pinMode(Relay_6, LOW);
pinMode(Relay_8, LOW);
pinMode(Relay_3, HIGH);
pinMode(Relay_8, HIGH);
delay(1000);
pinMode(Relay_3, LOW);
pinMode(Relay_8, LOW);
}
void loop() {
bool getTime(const char *str)
{
int Hour, Min, Sec;
if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}
bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;
if (sscanf(str, "%s %d %d", &Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++) {
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}
/*
// Is someone pressing the rotary switch?
if ((!digitalRead(PinSW))) {
virtualPosition = 10;
while (!digitalRead(PinSW))
delay(10);
Serial.println("Reset");
}
// If the current rotary switch position has changed then update everything
if (virtualPosition != lastCount) {
// Write out to serial monitor the value and direction
Serial.print(virtualPosition > lastCount ? "Up :" : "Down:");
Serial.println(virtualPosition);
// Keep track of this new value
lastCount = virtualPosition ;
}
*/
Is anybody familiar with this issue? Any help is greatly appreciated
SetTime.ino (1.64 KB)
Irrigation_Controller_7.ino (2.87 KB)