school bell

Can any one help? how can we set multiple alarms(minimum 30) by using arduino uno,ds3231 rtc and 3 push buttons.

please explain how can we do

  • look for the earliest enabled alarm time after the current time
  • program this alarm time into the alarm registers of the RTC

ok sir. please see this coding,is this right to call nearest alarm.
void loop()
{
address=0;
DateTime now = rtc.now();
displayTime(); // display the real-time clock data on the Serial Monitor,
delay(1000);
Al=EEPROM.read(address);
hours1 = EEPROM.read(address+1);//read set alarm hours from address.
minut = EEPROM.read(address+2);//read set alarm minutes from address.
address=address+3;
if (Addr == 512)
Addr = 0;
delay(50);
alarm();

}
void alarm()
{
int hrc=60,mnc=60;
DateTime now = rtc.now();
Serial.print(address);
Al=EEPROM.read(address);
hours1 = EEPROM.read(address+1);//read set alarm hours from address.
minut = EEPROM.read(address+2);//read set alarm minutes from address.
if(hours1>now.hour())
{if(hours1<hrc)
{
hrc=hours1;
mnc=minut;
}
else if(hours1=hrc)
{ if(minut<mnc)
hrc=hours1;
mnc=minut;

}
}
else if(hours1=now.hour())
{
if(minut>now.minute())
{
if(minut<mnc)

hrc=hours1;
mnc=minut;
}
}

}

and sir want to set minimum 30 alarms in a day

start_hours and start_minutes: time from when to search the next alarm
sir it is creating confusion that it is first alarm set or current time(now.hour())

i’m writing alarms on EEPROM like this:
do
{
EEPROM.write(Addr, Al);// write first alarm number
Addr=Addr+1; // go to next eeprom address
hours1 = HOUR; // generate a hour value which is to be written on second address
EEPROM.write(Addr, hours1); // write the value to the new address of eeprom
Addr=Addr+1; //switch on next address.
minut = MINUT; //generate a minute value which is to be written on third address
EEPROM.write(Addr, minut); //write the value to the new address of eeprom
Addr=Addr+1;
Al++; // ready for next alarm details
}
while (Al<31);

sir it is not working properly.when we are comparing alarm_time to set alarm_time then it is written as if(alarm_time< start_time) and
.
.
.
.
if(alarm_time<found_alarm_time)
i want to say that when we will set alarm time then it will always higher than start time(current time)(in 24 hours) so why we are using like this.

OK got it.... thank you sir.

but sir now again a problem is arising when i'm using found_alarm_time to ring the buzzer it is not working.i'm using findNextAlarmTime function in setup and match function in loop.
void match()
{
DateTime now = rtc.now();
if( found_alarm_time == 60now.hour()+now.minute()) //compare found alarm time value to the current value of time
{
beep();
beep();
beep();
beep();
lcd.clear();
lcd.print("Wake Up........");
lcd.setCursor(0,1);
lcd.print("Wake Up.......");
beep();
beep();
beep();
beep();
delay(1000);
}
}
/
function to buzzer indication */
void beep()
{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer, LOW);
delay(500);
}
is it correct?

OK sir but then we will have to change the earlier programming and when i’m replacing found_alarm_time by p_found_alarm_hours and p_found_alarm_minutes,it is not working.

void findNextAlarmTime(now.hour(), now.minute(), &next_alarm_hours, &next_alarm_minutes);

it is showing error-
variable or field 'findNextAlarmTime' declared void

ok sir.
if( (next_alarm_hours == now.hour()) && (next_alarm_minutes == now.minute())) {
when we are comparing for alarm(next_alarm_hours & next_alarm_minutes) then there is no need of found_alarm_time.

now also it is not able to match with set alarm time

earlier logic is not working.

I’m using int hours1 and minut to store the alarm time value(ex 6:00 am,6:30 am etc, where hours1=6, minut=00 and next hours1=6 and minut=30)
*p_found_alarm_hours = 0xFF;
*p_found_alarm_minutes = 0xFF;
as you said that *p_found_alarm_hours and *p_found_alarm_minutes are used to tell the function where to store the result and we should use result not pointers
and next you said-
static uint8_t next_alarm_hours = 0xFF;
static uint8_t next_alarm_minutes = 0xFF;
this is creating confusion

static uint8_t next_alarm_hours = 0xFF;
static uint8_t next_alarm_minutes = 0xFF;
these variables can't be able to use outside the current function.

Hi;
I would like this program with the schema if possible; I am starting in arduino
thank you.