#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
RTC_DS1307 DS1307;
LiquidCrystal_I2C LCD(0x27,16,2);
DateTime casD;
byte sees = 0;
bool menu = 0;
int secs;
int mins;
int hours;
int days;
int months;
int years;
void setup(){
LCD.init();
LCD.backlight();
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
DS1307.begin();
DS1307.adjust(DateTime(__DATE__, __TIME__));
}
void loop(){
casD = DS1307.now();
if (!digitalRead(11)){
menu = true;
sees = 1;
mins = casD.minute();
hours = casD.hour();
days = casD.day();
months = casD.month();
years = casD.year();
delay(250);
}
if (!menu){
Zero();
}
if (menu){
switch (sees){
case 1: Editmins();
break;
case 2: Edithours();
break;
case 3: Editdays();
break;
case 4: Editmonths();
break;
case 5: Edityears();
break;
case 6: Ende();
break;
}
}
}
void Zero() {
LCD.setCursor(0,0);
LCD.print(" ");
LCD.print(casD.hour());
LCD.print(":");
LCD.print(casD.minute());
LCD.print(" ");
LCD.setCursor(0,1);
LCD.print(" ");
LCD.print(casD.day());
LCD.print(".");
LCD.print(casD.month());
LCD.print(".");
LCD.print(casD.year());
LCD.println(" ");
}
void Editmins() {
LCD.setCursor(0,0);
LCD.print(" ");
LCD.print("EDITING MINS ");
LCD.setCursor(0,1);
LCD.print(hours < 10 ? "0" + String(hours) : hours);
LCD.print(":");
LCD.print(mins < 10 ? "0" + String(mins) : mins);
LCD.print(" ");
if (!digitalRead(10)){
mins--;
mins < 0 ? mins = 59 : mins;
delay (200);
}
if (!digitalRead(9)){
mins++;
mins > 59 ? mins = 0 : mins;
delay (200);
}
if (!digitalRead(11)){
delay(200);
sees = 2;
Edithours();
}
}
void Edithours() {
LCD.setCursor(0,0);
LCD.print(" ");
LCD.print("EDITING HOURS ");
LCD.setCursor(0,1);
LCD.print(hours < 10 ? "0" + String(hours) : hours);
LCD.print(":");
LCD.print(mins < 10 ? "0" + String(mins) : mins);
if (!digitalRead(10)) {
hours--;
hours < 0 ? hours = 23 : hours;
hours > 23 ? hours = 0 : hours;
delay (200);
}
if (!digitalRead(9)){
hours++;
hours > 59 ? hours = 0 : hours;
delay (200);
}
if (!digitalRead(11)){
delay(200);
sees = 3;
Editdays();
}
}
void Editdays() {
LCD.setCursor(0,0);
LCD.print(" ");
LCD.print("EDITING DAYS ");
LCD.setCursor(0,1);
LCD.print(days < 10 ? "0" + String(days) : days);
LCD.print(".");
LCD.print(months < 10 ? "0" + String(months) : months);
LCD.print(".");
LCD.print(years < 10 ? "0" + String(years) : years);
if (!digitalRead(10)){
days--;
days < 0 ? days = 31 : days;
days > 31 ? days = 0 : days;
delay (200);
}
if (!digitalRead(9)){
days++;
days > 31 ? days = 0 : days;
delay (200);
}
if (!digitalRead(11)){
delay(200);
sees = 4;
Editmonths();
}
}
void Editmonths(){
LCD.setCursor(0,0);
LCD.print(" ");
LCD.print("EDITING MONTHS ");
LCD.setCursor(0,1);
LCD.print(days < 10 ? "0" + String(days) : days);
LCD.print(".");
LCD.print(months < 10 ? "0" + String(months) : months);
LCD.print(".");
LCD.print(years < 10 ? "0" + String(years) : years);
if (!digitalRead(10)){
months--;
months < 0 ? months = 12 : months;
months > 12 ? months = 0 : months;
delay (200);
}
if (!digitalRead(9)){
months++;
months > 12 ? months = 0 : months;
delay (200);
}
if (!digitalRead(11)){
delay(200);
sees = 5;
Edityears();
}
}
void Edityears(){
LCD.setCursor(0,0);
LCD.print(" ");
LCD.print("EDITING YEARS ");
LCD.setCursor(0,1);
LCD.print(days < 10 ? "0" + String(days) : days);
LCD.print(".");
LCD.print(months < 10 ? "0" + String(months) : months);
LCD.print(".");
LCD.print(years < 10 ? "0" + String(years) : years);
if (!digitalRead(10)){
years--;
delay (200);
}
if (!digitalRead(9)){
years++;
delay (200);
}
if (!digitalRead(11)){
delay(200);
sees=6;
Ende();
}
}
void Ende() {
LCD.clear();
LCD.setCursor(0, 0);
LCD.print(" ");
LCD.print("Je to tam sefe");
sees=0;
DS1307.adjust(DateTime(years, months, days, hours, mins, 0));
delay(2000);
menu = false;
loop();
}