#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
RTC_DS1307 rtc;
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int butpos = 9;
int butneg = 8;
int oldvalpos = HIGH;
bool oldvalneg = HIGH;
void setup() {
// put your setup code here, to run once:
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
lcd.init();
lcd.backlight();
pinMode(butpos, INPUT_PULLUP);
pinMode(butneg, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
delay(500);
if (digitalRead(butpos) != oldvalpos) {
if (digitalRead(butpos)== LOW){
DateTime newTime = DateTime(now.year(), now.month(), now.day(), now.hour(),
(now.minute() + 1) % 60, now.second()); // Увеличение минут
rtc.adjust(newTime);
}
oldvalpos = digitalRead(butpos);
}
if (digitalRead(butneg) != oldvalneg) {
if (digitalRead(butneg)== LOW){
DateTime newTime = DateTime(now.year(), now.month(), now.day(), now.hour(),
(now.minute() - 1) % 60, now.second()); // уменьшение минут
rtc.adjust(newTime);
}
oldvalneg = digitalRead(butneg);
}
}