Timbre de escuela

Hola Buenas tardes. Estoy tratando de hacer un timbre para una escuela. El programa funciona bien pero después de un tiempo funciona deja de funcionar.
Paso el código y si alguien puede darme una mano por favor. Desde ya muchas gracias

#include "Relay.h"
#include <LiquidCrystal.h>
#include <Wire.h>
#include <DS3231.h>
#include <avr/wdt.h>

RTClib RTC;
Relay bell(3, true);
Relay bell2(10, true);
LiquidCrystal lcd(9, 8, 4, 5, 6, 7);

void turnOnBells(){
bell.turnOn();
bell2.turnOn();
}

uint8_t dow(unsigned long t)
{
return ((t / 86400) + 4) % 7;
}

void turnOffBells(){
bell.turnOff();
bell2.turnOff();
}

// duration of bell ring in seconds
int shortRingSeconds = 3;
int longRingSeconds = 6;

// Set alarm times (24-hour format)
struct Alarm {
int hour;
int minute;
bool triggered;
bool isLong;
};

// Secundaria
Alarm alarms[12] = {
{7, 40, false, true},
{9, 0, false, true},
{9, 10, false, true},
{10, 25, false, true},
{10, 35, false, true},
{11, 55, false, true},
{12, 5, false, true},
{13, 20, false, true},
{8, 20, false, false},
{9, 45, false, false},
{11, 15, false, false},
{12, 40, false, false},
};

const int manualRingPin = 11;
const int disableAlarmsPin = 12;
bool alarmsEnabled = true;

char buf1[20];

void setup() {
Serial.begin(9600);
bell.begin();
bell2.begin();
turnOffBells();
lcd.begin(16, 2);
Wire.begin();
pinMode(manualRingPin, INPUT_PULLUP);
pinMode(disableAlarmsPin, INPUT_PULLUP);
wdt_disable();
wdt_enable(WDTO_8S);
}

void loop() {
wdt_reset();
static unsigned long lastUpdateTime = 0; // To update the display periodically, not at every loop run
const unsigned long updateInterval = 1000; // Update interval set to 1 second
unsigned long currentMillis = millis();

// Update the display only once every second to avoid flicker and unnecessary processing
if (currentMillis - lastUpdateTime >= updateInterval) {
lastUpdateTime = currentMillis;
// Get current time

DateTime now = RTC.now();
int currentHour = now.hour();
int currentMinute = now.minute();
int currentSecond = now.second();
int currentDay = now.day();
int currentMonth = now.month();
int currentYear = now.year() - 2000;
int currentDoW = dow(now.unixtime());
sprintf(buf1, "%02d/%02d/%02d", currentDay, currentMonth, currentYear);
// Display current time on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ISP - ");
lcd.setCursor(8, 0);
lcd.print(buf1);

lcd.setCursor(0, 1);
// Check disable alarms override
if (digitalRead(disableAlarmsPin) == LOW || currentDoW == 0 || currentDoW == 6) {
alarmsEnabled = false;
lcd.print("Receso ");
} else {
alarmsEnabled = true;
lcd.print("On ");
}
lcd.setCursor(8, 1);
if (currentHour < 10) lcd.print('0');
lcd.print(currentHour);
lcd.print(':');
if (currentMinute < 10) lcd.print('0');
lcd.print(currentMinute);
lcd.print(':');
if (currentSecond < 10) lcd.print('0');
lcd.print(currentSecond);
// Check manual ring override
if (digitalRead(manualRingPin) == LOW) {
turnOffBells();
} else {
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("TIMBRE MANUAL");
turnOnBells();
}

// Check if it's time to trigger any alarms
if (alarmsEnabled) {
for (int i = 0; i < 12; i++) {
if (!alarms[i].triggered && currentHour == alarms[i].hour && currentMinute == alarms[i].minute) {
turnOnBells();
lcd.setCursor(0, 1);
lcd.print("TIMBRE");
if (alarms[i].isLong) {
delay(longRingSeconds * 1000);
}else{
delay(shortRingSeconds * 1000);
}
turnOffBells();
alarms[i].triggered = true;
// delay(60000); // Wait 1 minute before checking alarms again
} else if (currentHour != alarms[i].hour || currentMinute != alarms[i].minute) {
alarms[i].triggered = false; // Reset the triggered state for the next day
}
}
}
}

}

:warning:

He trasladado su tema de una categoría de idioma inglés del foro a la categoría International > Español .

En adelante por favor usar la categoría apropiada a la lengua en que queráis publicar. Esto es importante para el uso responsable del foro, y esta explicado aquí la guía "How to get the best out of this forum".
Este guía contiene mucha información útil. Por favor leer.

De antemano, muchas gracias por cooperar.

Moderador:
Por favor, lee las Normas del foro y edita tu código/error usando etiquetas de código.
Ve a edición, luego selecciona todo el código que has publicado, lo cortas y click en (<CODE/>)



Cuando lo hagas, yo responderé.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.