I am trying to write a function to store the date and time data from an RTC module. I have used char arrays to implement the function. I get "declaration of 'varDay' as array of references" error upon compilation.
I am still learning about char arrays and manipulating them so may be I am making a very obvious mistake. Could you please explain what I am doing wrong?
#include <RTClib.h>
RTC_DS3231 rtc;
void setup() {
Serial.begin(115200);
#ifndef ESP8266
while (!Serial); // wait for serial port to connect. Needed for native USB
#endif
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
unsigned long newTime = millis();
static unsigned long oldTime = 0;
char varYear [] = "1234";
char varMonth [] = "00";
char varDay [] = "00";
char varHour [] = "00";
char varMinute [] = "00";
char varSecond [] = "00";
unsigned int varEpoch;
char varDate [] = "123456789";
char varTime [] = "12345678";
char dash [] = "-";
char colon [] = ":";
if (newTime - oldTime >= 60000) {
oldTime = newTime;
getDate(varDay, varMonth, varYear, varDate, dash, colon);
}
}
void getDate (char &varDay[3], char &varMonth[3], char &varYear[5], char &varDate[11], char &dash[2], char &colon[2]) {
DateTime now = rtc.now();
strcpy (varDay, now.day());
strcpy (varMonth, now.month());
strcpy (varYear, now.year());
strcat (varDate, varDay) ;
strcat (varDate, dash);
strcat (varDate, varMonth);
strcat (varDate, dash);
strcat (varDate, varYear)
Serial.println(varDate);
}