Hey everyone, I am working on a system which stores the time and date when a key is pressed and returns it when another key is pressed.
I am using an Arduino Uno and a Ds 1307 Real Time Clock.
I began by taking the example given in the rct library and adapting it to meet what I want to achieve.
It worked in storing and returning the date and time but it broke after I changed something which I can't figure out. It shows an error which says: "too many initializers for 'char []'".
I left the code for a short while due to schedule but now I can't remember what I changed that broke it.
I have gone through over and over.
#include <Keypad.h>
#include <EEPROM.h>
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tues", "Wed", "Thu", "Fri", "Sat"};
char mymonth2[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"};
char lasttime[10] = {};
char lastdate;
char day_of_week[4] = {};
String mysecond, myminute, myhour, myhour2, myday, mymonth, myyear, mytime, mydate, am, datetime;
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = 1, d7 = 0;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const byte numRows = 4; //number of rows on the keypad
const byte numCols = 4; //number of columns on the keypad
//The keymap for the keypad
char keymap[numRows][numCols] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
char keypressed;
byte rowPins[numRows] = {9, 8, 7, 6}; //Rows 0 to 3 //if you modify your pins you should modify this too
byte colPins[numCols] = {5, 4, 3, 2}; //Columns 0 to 3
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
void setup ()
{
lcd.begin(20, 4);
if (! rtc.begin()) {
lcd.print("Couldn't find RTC");
while (1);
}
}
void stringconversions() {
DateTime now = rtc.now();
//Here, the time details are converted to strings to be printed later on
myhour = String(now.hour(), DEC);
if (myhour.toInt() >= 12){
myhour2 = myhour.toInt() - 12;
myhour2 = String(myhour2);
am = "PM";
}
else{
myhour2 = myhour;
am = "AM";
}
myminute = String(now.minute(), DEC);
mysecond = String(now.second(), DEC);
//Here, the date details are also converted to strings to be printed too
myday = String(now.day(), DEC);
mymonth = String(now.month(), DEC);
mymonth = mymonth2[mymonth.toInt() + 1];
myyear = String(now.year(), DEC);
//Here, the strings for date and time are concatenated together
mytime = myhour2 + ":" + myminute + ":" + mysecond + " " + am;
mydate = myday + "/" + mymonth + "/" + myyear;
datetime = mytime + "" + "-" + "" + mydate;
}
void loop ()
{
keypressed = myKeypad.getKey();
//DateTime now = rtc.now();
//stringconversions();
//lcd.print(mytime);
// lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
if (keypressed == '0') {
stringconversions();
//itt is to increment the address for each character stored in the EEPROM
int att = 35;//this does the same for the characters in the array being saved
int itt;
for (itt = 0; itt < 21; itt++) {
EEPROM.write(att, datetime[itt]);
att++;
}
lcd.print(mydate);
}
if (keypressed == '1') {
int apx = 0;
int attt = 35;
int itt;
for (itt = 0; itt < 21; itt++) {
lasttime[apx] = EEPROM.read(attt);
apx++;
attt++;
}
lcd.clear();
//lcd.setCursor(0, 0);
lcd.print(lasttime);
}
}
I would really appreciate any help.