I am sorry I did not post the full code as I was waiting for that pc to do a windows update and seem to be taking a long time. I have the full code now.
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
RTC_DS3231 rtc;
int bellPin = 10;
//int bellLED = 16;
// Time for hammer to hit bell
int x = 300; // hammer on pules
int y = 2000; // hammer off and wait
int z = 3000; // wait between sets
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
char monthsOfTheYear[12][12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
void setup () {
Wire.begin();
// Serial.begin(9600);
// initialize digital pin bellLED as an output.
pinMode(bellPin, OUTPUT);
// pinMode(bellLED, OUTPUT);
setupLcd();
setupRtc();
// Use this to set the correct time on the RTC module
// setTime(2021, 3, 18, 22, 58, 0);
}
void loop () {
DateTime now = rtc.now();
// Date row
lcd.setCursor(1, 0);
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(" ");
lcd.print(now.day() < 10 ? "0" + String(now.day()) : now.day());
lcd.print(" ");
lcd.print(monthsOfTheYear[now.month() - 1]);
lcd.print(" ");
lcd.print(now.year());
// Time row
lcd.setCursor(4, 1);
lcd.print(now.hour() < 10 ? "0" + String(now.hour()) : now.hour());
lcd.print(":");
lcd.print(now.minute() < 10 ? "0" + String(now.minute()) : now.minute());
lcd.print(":");
lcd.print(now.second() < 10 ? "0" + String(now.second()) : now.second());
delay(100);
if (now.hour() == 12 && now.minute() == 00 && now.second() == 00){
angelus();
}
else if (now.hour() == 18 && now.minute() == 00 && now.second() == 00){
angelus();
}
}
void bell(){
digitalWrite(bellPin, HIGH);
delay(x);
digitalWrite(bellPin, LOW);
}
void bellx3(){
bell();
delay(y);
bell();
delay(y);
bell();
delay(z);
}
void bellx9(){ // REPEAT THIS 3 TIMES FOR 9 BELLS
bell();
delay(y);
bell();
delay(y);
bell();
delay(y);
}
void angelus() {//set 1 of 3 rings
bellx3();
bellx3();
bellx3();
bellx9();
bellx9();
bellx9();
}
void setupLcd() {
// put your setup code here, to run once:
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
//lcd.print("Booting...");
}
void setupRtc() {
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
}
void setTime(int y, int m, int d, int h, int i, int s) {
Serial.println("Setting time");
rtc.adjust(DateTime(y, m, d, h, i, s));
}
I am using the same pin as the led is connected to at the moment to make the bell ring via an optocoupler.