#include "Arduino.h"
#include "uRTCLib.h"
#include "Wire.h"
#include "uEEPROMLib.h"
uRTCLib rtc(0x68);
uEEPROMLib eeprom(0x50);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(100);
URTCLIB_WIRE.begin();
rtc.set(45, 59, 23, 5, 30, 1, 23);
// rtc.set(second, minute, hour, dayOfWeek, dayOfMonth, month, year)
// set day of week (1=Sunday, 7=Saturday)
Wire.begin();
int inttmp = 32123;
float floattmp = 3.1416;
char chartmp = 'A';
char c_string[] = "Hello"; //23
int string_length = strlen(c_string);
Serial.println("Writing into memory...");
if (!eeprom.eeprom_write(8, chartmp)) {
Serial.println("char was stored correctly.");
} else {
Serial.println("char was stored correctly.");
}
if (!eeprom.eeprom_write(33, (byte *) c_string, strlen(c_string))) {
Serial.println("string was stored correctly.");
} else {
Serial.println("string was stored correctly.");
}
if (!eeprom.eeprom_write(0, inttmp)) {
Serial.println("int was stored correctly.");
} else {
Serial.println("int was stored correctly.");
}
if (!eeprom.eeprom_write(4, floattmp)) {
Serial.println("float was stored correctly.");
} else {
Serial.println("float was stored correctly.");
}
delay(2000);
Serial.println("");
Serial.println("Reading memory...");
Serial.print("int: ");
eeprom.eeprom_read(0, &inttmp);
Serial.println(inttmp);
Serial.print("float: ");
eeprom.eeprom_read(4, &floattmp);
Serial.println((float) floattmp);
Serial.print("char: ");
eeprom.eeprom_read(8, &chartmp);
Serial.println(chartmp);
Serial.print("string: ");
eeprom.eeprom_read(33, (byte *) c_string, string_length);
Serial.println(c_string);
Serial.println();
delay(2000);
}
void loop() {
// put your main code here, to run repeatedly:
rtc.refresh();
Serial.print("Current Date & Time: ");
Serial.print(rtc.day());
Serial.print('/');
Serial.print(rtc.month());
Serial.print('/');
Serial.print(rtc.year());
Serial.print(" (");
Serial.print(daysOfTheWeek[rtc.dayOfWeek()-1]);
Serial.print(") ");
Serial.print(rtc.hour());
Serial.print(':');
Serial.print(rtc.minute());
Serial.print(':');
Serial.println(rtc.second());
delay(500);
}