#include <LiquidCrystal.h>
#include <DS1307RTC.h>
#define tlacitko 10 //Dočasně
int owo = 0;
int led = 9; //Dočasně
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0; // Odpor R1 (100K)
float R2 = 10000.0; // Odpor R2 (10K)
int value = 0;
int a[5] = {};
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
boolean svetlo = false; //Dočasně
boolean enable; //Dočasně
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
Serial.begin(9600);
pinMode(analogInput, INPUT);
pinMode(led, OUTPUT); //Dočasně
pinMode(tlacitko, INPUT_PULLUP); //Dočasně
lcd.begin(16, 2);
lcd.setCursor(1, 0);
lcd.print("Renault Power");
lcd.setCursor(0, 1);
lcd.print("-Mareckovo LGL-");
delay(5000); // Čas uvítání
lcd.clear();
rtc_setup();
}
void loop() {
//----------------------------------------
if (digitalRead(tlacitko) && enable == false){
if (svetlo) {
svetlo = false;
}
else {
svetlo = true;
}
digitalWrite(led, svetlo);
enable=true;
}
if (digitalRead(tlacitko)==false)
{
enable=false;
}
//----------------------------------------
if (millis() - previousMillis >= 5000) {
// save the last time you blinked the LED
previousMillis = millis();
owo++;
}
switch(owo){
case 0:
time();
break;
case 1:
lcd.clear();
owo++;
break;
case 2:
messure();
break;
case 3:
lcd.clear();
owo = 0;
break;
}
}
void messure(){
lcd.setCursor(0, 0);
lcd.print("Markovo volty:");
// Čtení vstupních analogových hodnot
value = analogRead(analogInput);
vout = (value * 5) / 1024.0;
vin = vout / (R2 / (R1 + R2));
Serial.println(vin);
if (vin < 0.09)
{
vin = 0.0;
}
lcd.setCursor(0, 1);
lcd.print("Napeti V :");
lcd.print(vin);
delay(300); // Čas změny hodnoty na displeji
}
void time(){
lcd.setCursor(0, 0);
lcd.print("Markovo cas:");
lcd.setCursor(4, 1);
lcd.print((String)hour() + ":");
if (minute() < 10) {
lcd.print("0");
}
lcd.print((String)minute() + ":");
if (second() < 10) {
lcd.print("0");
}
lcd.print(second());
}
void rtc_setup() {
setSyncProvider(RTC.get); // the function to get the time from the RTC
if (timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
if (timeStatus() == timeSet) {
Serial.print(hour());
serial_printDigits(minute());
serial_printDigits(second());
Serial.println((String)" " + day() + "." + month() + "." + year());
}
else {
Serial.println("The time has not been set. Please run the Time\r\n");
delay(4000);
}
}
void serial_printDigits(int digits) {
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}