#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 1); // Set the LCD I2C address
int pinYear = 7;
int pinDay = 2;
int pinMonth = 4;
int pinHour = 8;
int pinMinute = 5;
int pinBregg = 3;
float AngleBregg=10;
int Y;
int M;
void setup()
{
pinMode(8,INPUT);//инициализация портов
lcd.begin(20,4); // Initialize LCD
lcd.setCursor(3,0); // Set the cursor at the 4th column and 1st row
lcd.print("Hello!");
lcd.setCursor(8,1); // Set the cursor at the 9th column and 2nd row
lcd.print("AngleBregg");
lcd.setCursor(0,2); // Set the cursor at the 1st column and 3rd row
lcd.print("This is a demo text");
lcd.setCursor(8,3); // Set the cursor at the 9th column and 4th row
lcd.print("****");
delay(3000);
lcd.clear();
analogReference(INTERNAL); // Встановлення опорної напруги АЦП 1,1В
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
void loop () {
DateTime now = rtc.now();
lcd.setCursor(0, 0);
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(" ");
//lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
//lcd.print(") ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
int Xray0 = analogRead(A0);
float voltage = Xray0 * (1.1 / 1024.0)*1000;
lcd.setCursor(0, 1);
Serial.println(voltage);
if(digitalRead(pinBregg) == HIGH) // если кнопка нажата
{ AngleBregg++; }
else // иначе
{
//digitalWrite(LedPin,LOW); // светодиод отключаем
}
if(AngleBregg>40)
{ AngleBregg =10; }
//if(digitalRead(pinDay)==HIGH)
//{ setTime(-1, -1, -1, 1, -1, -1);}
if (digitalRead(pinYear) == HIGH) {
Y = now.year();
if(Y>2030) { Y = 2022 ;}
rtc.adjust(DateTime(Y+1, now.month(), now.day(), now.hour(), now.minute(), 0));
}
if (digitalRead(pinMonth) == HIGH) {
rtc.adjust(DateTime(now.year(), now.month()+1, now.day(), now.hour(), now.minute(), 0));
}
if (digitalRead(pinMonth) == HIGH) {
rtc.adjust(DateTime(now.year(), now.month()+1, now.day(), now.hour(), now.minute(), 0));
}
if (digitalRead(pinDay) == HIGH) {
rtc.adjust(DateTime(now.year(), now.month(), now.day()+1, now.hour(), now.minute(), 0));
}
if (digitalRead(pinHour) == HIGH) {
rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour()+1, now.minute(), 0));
}
if (digitalRead(pinMinute) == HIGH) {
rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), now.minute()+1, 0));
}
lcd.print(voltage);
lcd.print(':');
lcd.print(AngleBregg);
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.println();
delay(50);
}