Have this code below working successfully now for a couple of years thanks to assistance from the good people here, however it has one drawback. The kids in Thailand can follow the English birthday description to some extent but wife's mum (and others) have no idea what so ever.
So thought perhaps changing the code and building a complete new unit to allow a TFT display to show a photo of the "birthday person" rather than the English text detail on the old 1602 LCD.
Question is, would following the same/similar logical code arrangement and using an SD card with photos which could be displayed on the birthday date work in the same way by monitoring the RTC?
This plus display an analog clock on "no-birthdays today ".
Original 1602 code.
[code]
/* Use Arduino Promini and DS3231 RTC
Unsolder 201 resistor from DS3231 module if not using rechargable memory battery
Button on pin 7 is just to show alarm LED and "Birthday Test" text
Button on pin 9 is to scan through the names and dates stored
LCD used is 1602 I2C
Adjustment Required......Go to Line 41 below and replace "xxx" with peoples name (can be capital letters)
Then Replace the 1,1 with their birthday DAY and then MONTH ...example is shown in the comments alongside
I had occasion to use the clock for Thailand and so I replaced the hours and the year with the following
Added 543 years to current year in Grigorial Calendar and subtracted 3 hours from the current time here to give correct time there
Example is commented out .....Line 133, 134 and 135 for hours......Line 158, 159 and 160 for the year
*/
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include "RTClib.h"
RTC_DS1307 rtc;
hd44780_I2Cexp lcd;
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
byte scanButton = 9;
byte buttonState;
byte ledPin = 8;
byte testButton = 7;
byte tbState;
const long interval (200);
const char daysOfTheWeek[7][12] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}; // changed char to const char to move from SRAM....1/8/2022
const char monthOfYear[13][5] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEPT", "OCT", "NOV", "DEC"};// changed char to const char to move from SRAM....1/8/2022
struct People { // set up the struct
char name[10];
byte day;
byte month;
};
const People birthdays[] = {
{"xxx", 1, 1}, // my people name, day and month of birthday (Up to 7 letters in name......next is day....next is month
{"xxx", 1, 1}, // example Jane on 21 February would be ... {"Jane",21,2},
{"xxx", 1, 1},
{"xxx", 1, 1},
{"xxx", 1, 1},
{"xxx", 1, 1},
{"xxx", 1, 1},
{"xxx", 1, 1}
};
void setup() {
Serial.begin(9600); // for serial monitor
pinMode(scanButton, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(testButton, INPUT_PULLUP);
lcd.begin(LCD_COLS, LCD_ROWS); // added this for LCD...hd44780 3/8/2022 ...end of added/changed code for hd44780 library
lcd.backlight(); // to power ON the back light
if (! rtc.begin()) // real time clock check
{
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(2022, 10, 9, 6, 28, 0));// to set the time manually............ year (Thai plus 543...month....day.....hour(24) ...minute...second)
digitalWrite(ledPin, LOW); // make sure led is off to begin with
}
void loop() {
buttonState = digitalRead(scanButton); // check if scan button changed
if (buttonState == LOW) {
scanBirthdays();
}
tbState = digitalRead(testButton); //check if test button has been pressed
if (tbState == LOW) {
testButtonCode();
}
DateTime now = rtc.now(); // check rtc
for (uint8_t x = 0; x < sizeof (birthdays) / sizeof(birthdays[0]); x++) { // loop through list ....const People birthdays
if ( birthdays[x].month == now.month() &&
birthdays[x].day == now.day()) { // see if any birthdays match todays day and month
for (int j = 0; j < 10; j++) {
digitalWrite(ledPin, HIGH); // flash LED 10 times
delay(interval);
digitalWrite(ledPin, LOW);
delay(interval);
}
lcd.setCursor(0, 0); //if they do then show on the LCD display
lcd.print(" HAPPY BIRTHDAY ");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(6, 1);
lcd.print(birthdays[x].name);
lcd.print(" ");
for (int i = 0; i < 10; i++) { //flash LED 10 times again
digitalWrite(ledPin, HIGH);
delay(interval);
digitalWrite(ledPin, LOW);
delay(interval);
}
}
else {
Clock(); // jump to display clock
} // placing clock here gives 8 second clock display
// if above for loop operates
}
}
//*************************************end of loop**************************************************
void Clock() {
// print bottom line on 16 x 2 display
DateTime now = rtc.now(); // check time on real time clock
lcd.setCursor(1, 1); // display on LCD
lcd.print("TIME");
lcd.print(" ");
if (now.hour() < 10) {
lcd.print("0");
}
lcd.print(now.hour()); //comment out to allow time set via pc with 3 hours less for Thailand time
//int thaiHour = now.hour()-3; //then comment in these 2 lines
//lcd.print(thaiHour); //similar below for the difference in Thailand years
lcd.print(':');
if (now.minute() < 10) { // "0" leading if less than 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(0, 0);
lcd.print(" ");
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(" ");
lcd.print(now.day());
lcd.print('/');
lcd.print(now.month());
lcd.print('/');
lcd.print(now.year()); // comment out this line for Thailand year
//int thaiYear = now.year() + 543; // Then comment in these next 2 lines.....Thai year = +543 years
//lcd.print(thaiYear);
lcd.print(" ");
delay(1000);
}
//*******************************end of "clock"******************************************************
void scanBirthdays() {
for (uint8_t x = 0; x < sizeof (birthdays) / sizeof(birthdays[0]); x++) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(birthdays[x].name); //scan the struct and look for names
lcd.print(" BIRTHDAY");
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.print(birthdays[x].day); //select the one that co-incides with the number through the for loop
lcd.print(" of ");
int monthValue = birthdays[x].month;
switch (monthValue) {
case 1:
lcd.print("JANUARY");
break;
case 2:
lcd.print("FEBRUARY");
break;
case 3:
lcd.print("March ");
break;
case 4:
lcd.print("April ");
break;
case 5:
lcd.print("MAY ");
break;
case 6:
lcd.print("JUNE ");
break;
case 7:
lcd.print("JULY ");
break;
case 8:
lcd.print("AUGUST ");
break;
case 9:
lcd.print("SEPTEMBER");
break;
case 10:
lcd.print("OCTOBER ");
break;
case 11:
lcd.print("NOVEMBER ");
break;
case 12:
lcd.print("DECEMBER");
break;
default:
lcd.print("ERROR ");
break;
}
delay(4000);
}
}
void testButtonCode() {
lcd.print(" HAPPY ");
lcd.setCursor (0, 1);
lcd.print(" BIRTHDAY TEST ");
for (int i = 0; i < 20; i++) { //flash LED 20 times
digitalWrite(ledPin, HIGH);
delay(interval);
digitalWrite(ledPin, LOW);
delay(interval);
}
}
//************************************program end***********************************************
[/code]