#include <PCD8544.h>
#include <Wire.h>
#include <RTClib.h>
static PCD8544 lcd;
RTC_DS3231 rtc;
const int buzzerPin = 9; // Connect buzzer to pin 9
// Define multiple alarms
const int numAlarms = 3;
const int alarmTimes[numAlarms][3] = {
{8, 30, 0}, // Alarm 1: 8:30:00
{9, 48, 0}, // Alarm 2: 9:48:00
{18, 15, 0} // Alarm 3: 18:15:00
};
void setup() {
// Initialize LCD and RTC
lcd.begin(84, 48);
pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output
if (!rtc.begin()) {
lcd.setCursor(0, 0);
lcd.print("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
lcd.setCursor(0, 0);
lcd.print("RTC lost power");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set the time to compile time
}
}
void loop() {
DateTime now = rtc.now();
// Clear screen and update time display
lcd.clear();
lcd.setCursor(3, 2);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
// Check if the current time matches any alarm
for (int i = 0; i < numAlarms; i++) {
if (now.hour() == alarmTimes[i][0] && now.minute() == alarmTimes[i][1] && now.second() == alarmTimes[i][2]) {
lcd.setCursor(3, 4);
lcd.print("ALARM!");
tone(buzzerPin, 1000); // Play sound at 1000Hz
delay(1000); // Sound duration
noTone(buzzerPin); // Stop sound
break; // Stop checking once an alarm matches
}
}
delay(1000); // Update every second
}Loading
nokia-5110
nokia-5110