#include <LiquidCrystal.h>
#include "RTClib.h"
LiquidCrystal lcd(12,11,10,9,8,7);
RTC_DS1307 rtc;
int button1 = A0;//sec
int button2 = A1;//min
int button3 = A2;//hour
int mSEC = 0;
int mMIN = 0;
int mHOUR = 0;
void setup() {
lcd.begin(16,2);
rtc.begin();
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
}
void loop() {
if(digitalRead(button3)== LOW){
mHOUR++;
if(mHOUR >= 60) mHOUR= 0;
}
if(digitalRead(button2)== LOW){
mMIN++;
if(mMIN >= 60) mMIN= 0;
}
if(digitalRead(button1)== LOW){
mSEC++;
if(mSEC >= 24) mSEC= 0;
}
textPrint(mSEC, mMIN, mHOUR);
delay(300);
}
void textPrint (int x, int y, int z){
lcd.clear();
char str[8];
sprintf (str, " %02d:%02d:%02d ", x, y, z);
lcd.setCursor(7,1);
lcd.print(str);
ura();
}
void ura(){
static int alarm = 0;
DateTime now = rtc.now();
int ure = now.hour();
int minute = now.minute();
int sekunde = now.second();
char ura[14];
sprintf (ura, " %02d:%02d:%02d ", ure, minute, sekunde);
lcd.setCursor(7,0);
lcd.print(ura);
if(sekunde == mSEC && minute == mMIN && ure == mHOUR){
alarm == HIGH;
}
else if (alarm && (sekunde > (mSEC + 15))) alarm = LOW;
digitalWrite(13, alarm);
}