Hallo Leute,
Ich habe mich vor ein paar Minuten angemeldet, da ich einen Tip brauche! Ich würde mich auch sehr für Verbesserungsvorschläge bedanken!
Ich habe einen DS1307 als Zeitgeber und gebe die Zeit (Und ein paar andere Informationen) über den Display aus.
Nun möchte ich aber die Zeit mit mehreren Buttons anpassen bekomme es aber nicht hin dieses so zu machen, dass sich die Zeit nicht auf 0 setzt (das Datum natürlich auch).
Ich habe schon probiert die Zeit des Arduinos mit dem Befehl "adjustTime(adjustment);" und dann mit "setTime(t);" die Lokale Zeit des Arduinos auf den DS1307 zu setzten, diese hat aber immer die Zeit zurück gesetzt
Hier ist mein Code:
unsigned long previousMillis_LCD = 0; //LCD Pages
unsigned long previousMillis_Zeit = 0; //Für Timer
unsigned long previousMillis_LCD_Helligkeit = 0; //LCD Helligkeit
#include <LiquidCrystal.h> //LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <Wire.h>
#include <Time.h> //Zeit
#include <DS1307RTC.h> //Zeit
#include "DHT.h" //Temperatur
#include <IRremote.h> //IR
#include <IRremoteInt.h>//IR
#define DHTPIN 7 //DHT
#define DHTTYPE DHT22 //DHT
DHT dht(DHTPIN, DHTTYPE); //DHT
int Status_Relay = LOW; //Deklariert Relay Status
int LCD_Helligkeit_Button = 53;//Deklariert LCD Helligkeits pin
int LCD_Helligkeit = 52; //Deklariert LCD Pin
int Status_LCD = 1; //Bildschirm ist "Gerade" an (1)
int LCD_Page_Button = 10; //LCD
int LCD_Page = 1; //Startseite des LCD Bildschirms
int RECV_PIN = 6; //IR Reciver Pin
decode_results results; //IR KP was das ist
IRrecv irrecv(RECV_PIN); //IR Setzt Reciver Pin
int relay1 = 8; //Relay Ausgabe
int relay2 = 9; //Relay Ausgabe
void setup() {
Serial.begin(9600);
dht.begin(); //Temperatur Lesen beginnt
irrecv.enableIRIn(); // Startet den receiver
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
lcd.begin(16, 2); //Startet LCD
pinMode(LCD_Helligkeit, OUTPUT); //Deklariert LCD als Ausgang
digitalWrite(LCD_Helligkeit, HIGH); //Schreibt LCD High
}
void loop() {
///////////////////////////////I N F R A R O T////////////////////////////////////////
if ((irrecv.decode(&results)) == true) {
//Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
//long int
long int decCode = results.value; //Setzt results auf decCode
///////////////////////////////I N F R A R O T////////////////////////////////////////
//////////////////////////////// T E M P E R A T U R /////////////////////////////////
float Temp = dht.readTemperature(); //long Temp = round(dht.readTemperature());
float Humidity = dht.readHumidity(); //long Humidity = round(dht.readHumidity());
//////////////////////////////// T E M P E R A T U R /////////////////////////////////
//////////////////////////////////// Z E I T /////////////////////////////////////////
tmElements_t tm;
if (RTC.read(tm)) {}
unsigned long Stunde = tm.Hour * 100;
unsigned long Minute = tm.Minute;
unsigned long DecZeit = Stunde + Minute;
//////////////////////////////////// Z E I T /////////////////////////////////////////
if (decCode == 16228447){
previousMillis_Zeit = millis();
}
if (millis() - previousMillis_Zeit > 900000){ //15 Minuten
if (DecZeit > 644 && DecZeit < 701 && Temp < 25 || DecZeit > 724 && DecZeit < 741 && Temp < 25){
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
}
else if (Status_Relay == 0){
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
}
}
if (decCode == 16195807 && Status_Relay == 0){
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
Status_Relay = 1;
previousMillis_Zeit = millis() + 900000;
}
else if (decCode == 16195807 && Status_Relay == 1){
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
Status_Relay = 0;
}
///////////////////////////////////S E R I A L/////////////////////////////////////
/*if (Serial){
Serial.print("Zeit: ");
Serial.print(tm.Hour);
Serial.print(":");
Serial.print(tm.Minute);
Serial.print(":");
Serial.print(tm.Second);
Serial.print(" Temperatur: ");
Serial.print(dht.readTemperature());
Serial.print("*C ");
Serial.print("Humidity: ");
Serial.print(dht.readHumidity());
Serial.print("% ");
Serial.println(decCode);
}
*/
///////////////////////////////////S E R I A L/////////////////////////////////////
///////////////////////////////// L C D ///////////////////////////////////////////
if (millis() - previousMillis_LCD > 500) { //0.5 Sekunden
previousMillis_LCD = millis();
if (digitalRead(LCD_Page_Button) == 1 && LCD_Page == 2){
LCD_Page = 1;
lcd.clear();
}
else if (digitalRead(LCD_Page_Button) == 1 && LCD_Page == 1){
LCD_Page = 2;
lcd.clear();
}
}
////////////////////////////// L C D P A G E 1 ////////////////////////////
if (LCD_Page == 1){
lcd.setCursor(0,0);
if (tm.Hour <= 9) lcd.print("0");
lcd.print(tm.Hour);
lcd.print(":");
if (tm.Minute <= 9) lcd.print("0");
lcd.print(tm.Minute);
lcd.print(":");
if (tm.Second <= 9) lcd.print("0");
lcd.print(tm.Second);
lcd.print(" ");
lcd.print(Temp,1); //1 für 1 Nachkommastelle
lcd.print((char)223); //Für ° Symbol
lcd.print("C");
lcd.setCursor(0,1);
if (tm.Day <= 9) lcd.print("0");
lcd.print(tm.Day);
lcd.print(".");
if (tm.Month <= 9) lcd.print("0");
lcd.print(tm.Month);
lcd.print(".");
if (tm.Year <= 9) lcd.print("0");
lcd.print(tm.Year - 30);
lcd.print(" ");
lcd.print(Humidity,0); //0 für 0 Nachkommastellen
lcd.print("%");
}
////////////////////////////// L C D P A G E 1 ////////////////////////////
////////////////////////////// L C D P A G E 2 ////////////////////////////
if (LCD_Page == 2){
lcd.setCursor(0,0);
lcd.print(" CODE ");
if (decCode > 2){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("CODE: ");
lcd.print(decCode);
}
}
////////////////////////////// L C D P A G E 2 ////////////////////////////
///////////////////////////////// L C D ///////////////////////////////////////////
//////////////////////////Z E I T A N P A S S U N G//////////////////////
/*if (decCode == 16187647){
//adjustTime(DateTime(__DATE__, __TIME__));
int secnd = tm.Second + 5;
setTime(tm.Hour,tm.Minute,secnd,tm.Day,tm.Month,tm.Year);
RTC.set(now());
}
if (decCode == 16220287){
adjustTime(-4);
RTC.set(now());
}
Serial.println(decCode);*/
//////////////////////////Z E I T A N P A S S U N G//////////////////////
////////////////////////L C D H E L I G K E I T/////////////////////////
if (millis() - previousMillis_LCD_Helligkeit > 500) { //0.5 Sekunden
previousMillis_LCD_Helligkeit = millis();
if (digitalRead(LCD_Helligkeit_Button) == 1 && Status_LCD == 0){
digitalWrite(LCD_Helligkeit, HIGH);
Status_LCD = 1;
}
else if (digitalRead(LCD_Helligkeit_Button) == 1 && Status_LCD == 1){
digitalWrite(LCD_Helligkeit, LOW);
Status_LCD = 0;
}
}
////////////////////////L C D H E L I G K E I T/////////////////////////
results.value = 0;
} //Ende Loop
Danke schonmal im vorraus!