Hello, this is my first post in this forum, any forum actually, so I am very sorry If I make mistakes. I have a code for a school project but no matter how many times I modify the code, error messages still come up and I do not know how to fix them. Can someone please help me?
THE CODE IS:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
// Set the LCD address to 0x3F for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
DS3231 rtc; // Initialize DS3231 instance
int Hour;
int Min;
int pset = 8; // Pushbutton for setting alarm
int phour = 9; // Pushbutton for hour
int pmin = 10; // Pushbutton for minutes
int pexit = 11; // Pushbutton for exit of set alarm
int buzzer = 6;
int h = 0; // Initialize alarm hour
int m = 0; // Initialize alarm minute
int buttonforset = 0; // Pushbutton state for setting alarm
int buttonforhour = 0; // Pushbutton state for hour
int buttonformin = 0; // Pushbutton state for minutes
int buttonforexit = 0; // Pushbutton for exit of set alarm
int activate = 0;
void setup() {
pinMode(pset, INPUT);
pinMode(phour, INPUT);
pinMode(pmin, INPUT);
pinMode(pexit, INPUT);
pinMode(buzzer, OUTPUT);
// Initialize LCD
lcd.begin();
lcd.backlight();
// Set the RTC date and time if necessary
rtc.setClockMode(false); // Use 24-hour mode
if (rtc.getYear() == 0) {
rtc.setYear(25); // Year (last two digits)
rtc.setMonth(1); // Month
rtc.setDate(17); // Day
rtc.setHour(4); // Hour
rtc.setMinute(51); // Minute
rtc.setSecond(30); // Second
}
}
void loop() {
bool h12, PM_time, Century;
Hour = rtc.getHour(h12, PM_time); // Retrieve hour
Min = rtc.getMinute(); // Retrieve minute
if (activate == 0) {
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.setCursor(6, 0);
if (Hour < 10) lcd.print('0'); // Add leading zero
lcd.print(Hour);
lcd.print(":");
if (Min < 10) lcd.print('0'); // Add leading zero
lcd.print(Min);
lcd.setCursor(0, 1);
lcd.print("Date: ");
lcd.setCursor(6, 1);
lcd.print(2000 + rtc.getYear()); // Add 2000 to get the full year
lcd.print("-");
if (rtc.getMonth(Century) < 10) lcd.print('0'); // Add leading zero
lcd.print(rtc.getMonth(Century));
lcd.print("-");
if (rtc.getDate() < 10) lcd.print('0'); // Add leading zero
lcd.print(rtc.getDate());
buttonforset = digitalRead(pset);
}
// Setting button pressed
if (buttonforset == HIGH) {
activate = 1;
lcd.clear();
delay(200);
}
while (activate == 1) {
lcd.setCursor(0, 0);
lcd.print("Set Alarm");
lcd.setCursor(0, 1);
lcd.print("Hour= ");
lcd.setCursor(9, 1);
lcd.print("Min= ");
buttonforhour = digitalRead(phour); // Set hour for alarm
if (buttonforhour == HIGH) {
h++;
if (h > 23) h = 0;
lcd.setCursor(5, 1);
lcd.print(h < 10 ? "0" : ""); // Add leading zero
lcd.print(h);
delay(200);
}
buttonformin = digitalRead(pmin); // Set minutes for alarm
if (buttonformin == HIGH) {
m++;
if (m > 59) m = 0;
lcd.setCursor(13, 1);
lcd.print(m < 10 ? "0" : ""); // Add leading zero
lcd.print(m);
delay(200);
}
buttonforexit = digitalRead(pexit); // Exit from set alarm mode
if (buttonforexit == HIGH) {
activate = 0;
lcd.clear();
delay(200);
}
lcd.setCursor(5, 1);
lcd.print(h < 10 ? "0" : ""); // Add leading zero
lcd.print(h);
lcd.setCursor(13, 1);
lcd.print(m < 10 ? "0" : ""); // Add leading zero
lcd.print(m);
}
// Check if it's time to trigger the alarm
if (Hour == h && Min == m) {
tone(buzzer, 400, 300); // Trigger buzzer for 300 ms
delay(500); // Wait before checking again
}
}
THE ERROR MESSAGES ARE:
C:\Users\romhe\AppData\Local\Temp\ccbs8WzA.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_sketch_jan17a.ino.cpp.o.1990':
<artificial>:(.text.startup+0x32): undefined reference to `LiquidCrystal_I2C::LiquidCrystal_I2C(unsigned char, unsigned char, unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\ccbs8WzA.ltrans0.ltrans.o: In function `setup':
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:33: undefined reference to `LiquidCrystal_I2C::begin()'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:34: undefined reference to `LiquidCrystal_I2C::backlight()'
C:\Users\romhe\AppData\Local\Temp\ccbs8WzA.ltrans0.ltrans.o: In function `loop':
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:54: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:56: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:63: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:65: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:80: undefined reference to `LiquidCrystal_I2C::clear()'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:85: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:87: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:89: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:96: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:106: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:115: undefined reference to `LiquidCrystal_I2C::clear()'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:119: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
C:\Users\romhe\AppData\Local\Temp\.arduinoIDE-unsaved2025017-13656-1o6e972.u2zu\sketch_jan17a/sketch_jan17a.ino:122: undefined reference to `LiquidCrystal_I2C::setCursor(unsigned char, unsigned char)'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1