Here is the code with the changes (marked with ************ ). Untested cause I don't have the hardware handy. Compiles with one warning, unrelated to the library change, that you might want to fix.
warning: initializer-string for array of chars is too long [-fpermissive]
char monthOfYear [13][4] = {" ", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEPT", "OCT", "NOV", "DEC"};
All that is changed is the #includes, the constructor, added the LCD geometry and the changed the begin function.
/* Birthday Clock uses DS1307 RTC ....maybe replace later with DS3231 for better time keeping but seems ok for now
Arduino pro mini with LEDs on pin 8 and the scan switch on pin 9
I2C to 16 x 2 LCD display and to the rtc
Can add extra birthdays if required in the "People birthdays[]" ..order is their name then the day then month of their birthday
In the "scan" there probably is a better way to look and the month number in People birthdays[] but I used simple "if"
So the program runs the "clock" showing current date on the top line and time on the bottom line
When a birthday comes up, it switches over to print "Happy Birthday" top line and their name on the second line
The LEDs flash at the beginning and end of this section and then goes back to the clock display for approx 8 seconds.
If the "scan" button " is pressed and held for a few seconds, the display will run through all the names and their day and month of their birthdate.
commented out serial prints were used during testing
rtc adjust can be un-commented for adjusting the time etc. either manually as I did for Thailand or automatically for your local time via PC
So uncomment whichever, adjust and upload, then comment out and reload again (with a battery in the rtc naturally)
*/
#include <Wire.h>
// ************ #include <LiquidCrystal_I2C.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
#include "RTClib.h"
RTC_DS1307 rtc;
// ************ LiquidCrystal_I2C lcd(0x27, 16, 2);
hd44780_I2Cexp lcd; // declare lcd object: auto locate & auto config expander chip
// ************ LCD geometry
const int LCD_COLS = 16;
const int LCD_ROWS = 2;
byte scanButton = 9;
byte buttonState;
byte ledPin = 8;
byte testButton = 7;
byte tbState;
//int ledState = 0;
const long interval (200);
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 // set up the struct
{
char name[10];
byte day;
byte month;
};
const People birthdays[] =
{
{"OPO", 21, 9}, // my people name, day and month of birthday
{"MUM", 14, 4},
{"NAD", 20, 1},
{"TON", 1, 6},
{"TOOSAFE", 12, 5},
{"JACKPOT", 7, 3},
{"SAWITA", 3, 6},
{"JEFF", 25, 2}
};
void setup ()
{
Serial.begin(9600); // for serial monitor
pinMode(scanButton, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(testButton, INPUT_PULLUP);
// ************ lcd.init (); // initialize the lcd
lcd.begin(LCD_COLS, LCD_ROWS);
//lcd.begin();
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, 6, 7, 13, 23, 0));// to set the time manually
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
// Serial.print("The year now is ");
// Serial.println(now.year());
// Serial.print("The month now is ");
// Serial.println(now.month());
// Serial.print("The day now is " );
// Serial.println(now.day());
for (uint8_t x = 0; x < sizeof (birthdays) / sizeof(birthdays[0]); x++) // loop through list ....const People birthdays
{
//Serial.print ("Checking ");
//Serial.println(birthdays[x].name);
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);
}
//Serial.print("Happy Birthday ");
//Serial.println(birthdays[x].name);
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());
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('/');
int thaiYear = now.year() + 543; // 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***********************************************
You do have warnings enabled in the IDE, don't you? File, Preferences, Compiler Warnings check box to All.
