Have been searching for a tutorial on how to retrieve a name from a struct on a person's birthday using a rtc DS1307 as a reference.
Have found many say the DS1307 is not a good choice but it is what I have at the moment to work with.
Seems to be plenty of "clock" and "single alarm" examples which are fine but does not include any struct or array reference.
Any pointers to a tutorial or examples are appreciated.
Found some reference to begin but quickly left me behind due to very little commenting or explanation, basically over my head.
The "button" is simply put in there to test code as it stands.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
byte button = 9;
byte buttonState;
//****************************** copied from other code on the inet here down
char daysOfTheWeek[7][12] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
char monthOfYear [13][4] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEPT", "OCT", "NOV", "DEC"};
struct People {
char name[10];
byte day;
byte month;
};
const People birthdays[] PROGMEM = {
{"OPO", 21, 9}, // my people name,day, month
{"MUM", 14, 4},
{"NAD", 20, 1},
{"TON", 1, 6},
{"TOOSAFE", 12, 5},
{"JACKPOT", 7, 3},
{"SAWITA", 3, 6},
{"JEFF", 25, 2},
{"PHI", 1, 1}
};
People Person;
//******************************* copied from other code on the inet here up
void setup ()
{
pinMode(button, INPUT_PULLUP);
Serial.begin(9600);
lcd.init (); // initialize the lcd
lcd.backlight();//To Power ON the back light
if (! rtc.begin())
{
lcd.print("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning())
{
lcd.print("RTC is NOT running!");
}
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));//auto update from computer time
//rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));// to set the time manually
}
void loop ()
{
buttonState = digitalRead(button); //just to test
if (buttonState == HIGH) { // " " "
Clock();
}
else { // " " "
/*code here to detect if a birthday has arrived and jump to
bdayDisplay(); ....... alarm buzz also every so often with a mute switch
or maybe just flash the display....
*/
bdayDisplay();
}
}
void Clock() {
// print bottom line on 16 x 2 display
DateTime now = rtc.now();
lcd.setCursor(1, 1);
lcd.print("TIME");
lcd.print(" ");
int thaiHour = now.hour() - 3;
if (now.hour() - 3 < 10) {
lcd.print("0");
}
lcd.print(thaiHour);
lcd.print(':');
if (now.minute() < 10) {
lcd.print("0");
}
lcd.print(now.minute());
lcd.print(':');
if (now.second() < 10) {
lcd.print("0");
}
lcd.print(now.second());
lcd.print(" ");
//print top line on 16 x 2 display
lcd.setCursor(1, 0);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(" ");
lcd.print(now.day());
lcd.print('/');
lcd.print(now.month());
lcd.print('/');
int thaiYear = now.year() + 543;
lcd.print(thaiYear);
lcd.print(" ");
}
void bdayDisplay() {
lcd.setCursor(0, 0);
lcd.print (" HAPPY BIRTHDAY ");
lcd.setCursor(0, 1);
lcd.print (" ---- OPO ----- ");
}