Arduino alarm clock using DS1302 and LCD keypad shield

Recently I have been working on an arduino alarm clock project. The clock and alarm works nicely, but I have had trouble implementing a snooze button into the project. Since I am using the LCD keypad shield, I wrote the program so that when the analog value of a pin reached a certain value, it would shut off the alarm and wait for a period of time. However, this did not work. Can anybody point me in the right direction as to how I can solve this problem/find a workaround?

My code so far:

#include <LiquidCrystal.h>
#include <DS1302RTC.h>
#include <Time.h>
int speaker = 22;




// Init the DS1302
// Set pins:  CE, IO,CLK
DS1302RTC RTC(45, 47, 49);

// Optional connection for RTC module
#define DS1302_GND_PIN 51
#define DS1302_VCC_PIN 53

// Init the LCD
//   initialize the library with the numbers of the interface pins
//            lcd(RS,  E, d4, d5, d6, d7, bl, polarity)
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()
{





  pinMode(28,OUTPUT);
  pinMode(22,OUTPUT);



  digitalWrite(28,LOW);

  // Setup LCD to 16x2 characters
  lcd.begin(16,2);

  // Activate RTC module
  digitalWrite(DS1302_GND_PIN, LOW);
  pinMode(DS1302_GND_PIN, OUTPUT);

  digitalWrite(DS1302_VCC_PIN, HIGH);
  pinMode(DS1302_VCC_PIN, OUTPUT);

  lcd.print("RTC activated");

  delay(500);

  lcd.clear();
  if (RTC.haltRTC())
    lcd.print("Clock stopped!");
  else
    lcd.print("Clock working.");

  lcd.setCursor(0,1);
  if (RTC.writeEN())
    lcd.print("Write allowed.");
  else
    lcd.print("Write protected.");

  delay (2000);

  // Setup time library  
  lcd.clear();
  lcd.print("RTC Sync");
  setSyncProvider(RTC.get);      // the function to get the time from the RTC
  if(timeStatus() == timeSet)
    lcd.print(" Ok!");
  else
    lcd.print(" FAIL!");

  delay ( 2000 );

  lcd.clear();


}

void loop()
{
  tmElements_t tm;




  lcd.setCursor(4, 0);
  print2digits(hour());
  lcd.print(":");
  print2digits(minute());
  lcd.print(":");
  print2digits(second());

  lcd.setCursor(0, 1);
  lcd.print(dayShortStr(weekday()));

  lcd.setCursor(5, 1);
  lcd.print(" ");
  print2digits(day());
  lcd.print("/");
  print2digits(month());
  lcd.print("/");
  lcd.print(year());








  if(hour() == 15 && minute() >= 45 && minute() < 55)
  {
    tone(speaker,1000,200);

  }





  // Warning!
  if (timeStatus() != timeSet) {
    lcd.setCursor(0, 1);
    lcd.print(F("RTC ERROR: SYNC!"));
  }
  delay(100);

}





void print2digits(int number) {
  if (number >= 0 && number < 10) {
    lcd.write('0');
  }
  lcd.print(number);
}

You don’t say how your program didn’t work, but here’s one possible way(untested) of implementing a snooze alarm. You can set up a snooze flag, which will turn off the alarm for 2 minutes.

Declare two new variables.

boolean snoozeFlag = false; 
unsigned long startSnooze;

To set the snoozeFlag you will poll the analog pin where the shield is connected(A0?) and have code that you activate with the correct analog read of the snooze button on the lcd shield.

if ( whatever analog read is true when the snooze button is pressed){
snoozeFlag = true;
startSnooze= millis();
}

Then, modify the 10 minute alarm code as follows

if(hour() == 15 && minute() >= 45 && minute() < 55)
  {
    if(snoozeFlag){
       noTone(speaker);
     //timer to clear the snoozeFlag
       if(millis() - startSnooze>120000UL){
       snoozeFlag = false;
      }
     }
    else{
       tone(speaker,1000,200);
     }

  }

As a further refinement, you may want to disallow the snoozeFlag if you are within three minutes of the end of the alarm period, and an alarm off button would be useful as well.