#include <Wire.h> 

#include "DFRobot_LCD.h"
DFRobot_LCD lcd(16,2);

int secs = 0;

int mins = 0;

int hrs = 0;

int y = 0;

String x;

int alarmh = 0;

int alarmmins = 0;

int alarmsecs = 0;

long Time;

 

const int buttonone = 7;

const int buttontwo = 5;

const int buttonthree = 12;

const int buttonfour = 3;

const int buzzer = 13;

void setup() {
  lcd.init();                      // initialize the lcd 
  
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(buzzer,OUTPUT);

pinMode(buttonone, INPUT);

pinMode(buttontwo, INPUT);

pinMode(buttonthree, INPUT);

pinMode(buttonfour, INPUT);

lcd.setCursor(0,0);
lcd.print("Time:");
lcd.setCursor(0,1);
lcd.print("Alarm:");
}

 

void loop() {

  // put your main code here, to run repeatedly:
Time = millis();
Serial.print(Time);
lcd.setCursor(6, 0);
lcd.print(hrs);

lcd.print(":");

lcd.print(mins);

lcd.print(":");

lcd.print(secs);

lcd.print(" " + x);

lcd.setCursor(7, 1);

lcd.print(alarmh);

lcd.print(":");

lcd.print(alarmmins);

lcd.print(":");
lcd.print(alarmsecs);

delay(1000);

secs = secs + 1;

if (secs > 59){

  secs = 0;

  mins = mins + 1;
  secs = 9;

}

if (mins > 59){

  mins = 0;

  hrs = hrs + 1;

}

if (hrs > 11){

  mins = 0;

  hrs = 0;

  y = y + 1;

  if (y == 2){

    y = 0;

  }

}

if (y == 0){

  x = "PM";

}

if (y == 1){

  x = "AM";

}

int activatebone = digitalRead(buttonone);

int activatebtwo = digitalRead(buttontwo);

int activatebthree = digitalRead(buttonthree);

int activatebfour = digitalRead(buttonfour);

if (activatebone == HIGH){

alarmh = alarmh + 1;

}

if (alarmh == 13){

  alarmh = 0;

}

else {

  alarmh = alarmh;

}

if (activatebtwo == HIGH){ 

  alarmmins = alarmmins + 1;

}

if (alarmmins == 61){

  alarmmins = 0;

}

else {

  alarmmins = alarmmins;

}

if (activatebthree == HIGH){

  mins = mins + 1;

}

if (mins == 61){

  mins = 0;

}

else {

  mins = mins;

}

if (activatebfour == HIGH){

  hrs = hrs + 1;
}

if (hrs == 13){

  hrs = 1;

}

else {

  hrs = hrs;

if (mins == alarmmins and hrs == alarmh and secs == alarmsecs){

  tone(buzzer,5000);
  delay(1500);        
  noTone(buzzer);    
  delay(1000);
  tone(buzzer,5000);
  delay(1500);        
  noTone(buzzer);    
  delay(1000);   tone(buzzer,5000);
  delay(1500);        
  noTone(buzzer);    
  delay(1000);        
secs = secs + 7;

}

}}