Hallo ich bin noch recht neu und habe ein Problem mit der Zeit Einstellung bei meiner Uhr dies läuft mit einem RTC Modul (ds3231).
Dabei ist das Problem das sich die Uhrzeit beim betätigen des Tasters um eine Stunde erhöhen soll. Das Funktioniert aber nicht da immer die gleiche Fehlermeldung erscheint. ( Variable nicht deklariert ) dabei handelt es sich um die Stunden Variabel die vom RTC Modul empfangen wird.
Es heißt immer das genau diese Variabel nicht deklariert ist, genauer gesagt wird das "now." nicht gefunden.
Hier die Fehler Meldung:
arduino_wood_clock__upir.ino:35:8: error: expected initializer before '.' token
int now.hour ={}
^
arduino_wood_clock__upir.ino: In function 'void loop()':
arduino_wood_clock__upir.ino:64:3: error: 'now' was not declared in this scope
now.hour() = now.hour()+1;
^~~
arduino_wood_clock__upir.ino:64:3: note: suggested alternative: 'pow'
now.hour() = now.hour()+1;
^~~
pow
#include <Arduino.h>
#include <U8g2lib.h>
#include "RTClib.h"
int now.hour ={}
int uhr = 0;
RTC_DS1307 rtc; // set the real time clock module
U8G2_MAX7219_32X8_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 10, /* dc=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE);
char time_string[10]; // string to hold the current time to be displayed
void setup(void) {
pinMode(2, INPUT);
pinMode(4, OUTPUT); // we are using pin 4 to power the real time clock module,
digitalWrite(4, HIGH); // since the +5V pin is already used for the display
u8g2.begin(); // begin function is required for u8g2 library
u8g2.setContrast(200); // set display contrast 0-255
if (! rtc.begin()) { // start the RTC module
abort();
}
// following line sets the RTC to the date & time this sketch was compiled
// uncomment this when uploading to Arduino, otherwise the time will be 0:00 and not increasing
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop(void) {
uhr = digitalRead(2);
if ( uhr == 1){
(now.hour()) = (now.hour())+1;
}
DateTime now = rtc.now(); // get current time
sprintf(time_string, "%02d:%02d", now.hour(), now.minute()); // add hours, colon symbol and minutes into a string
u8g2.setFont(u8g2_font_t0_11b_tn); // choose a suitable font
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(2, 8, time_string); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
delay(1000); // wait one second
}
Ich hoffe das mir jemand weiter helfen kann ich zerbreche mir deswegen schon seit geraumer Zeit den Kopf.
Im englischen Teil des Forum müssen die Beiträge und Diskussionen in englischer Sprache verfasst werden.
Deswegen wurde diese Diskussion in den deutschen Teil des Forums verschoben.
Du hast sehr viele Fehler drin und zudem auch die schlechteste lib ausgesucht, da die die wenigste Funktionalität bietet.
Der code könnte so aussehen, ABER!
Du wirst damit nicht glücklich. Deine Teste prellt, und Du merkst nicht, dass Du bereits auf die Taste gedrückt hast.
Du merkst nur alle Sekunde, dass Du auf die Taste drückst.
Sobald Du das delay() a Ende raus nimmst, geht das komplett schief.
#include <Arduino.h>
#include <U8g2lib.h>
#include "RTClib.h"
//int now.hour;
int uhr = 0;
RTC_DS1307 rtc; // set the real time clock module
U8G2_MAX7219_32X8_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 10, /* dc=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE);
char time_string[10]; // string to hold the current time to be displayed
void setup(void)
{
pinMode(2, INPUT);
pinMode(4, OUTPUT); // we are using pin 4 to power the real time clock module,
digitalWrite(4, HIGH); // since the +5V pin is already used for the display
u8g2.begin(); // begin function is required for u8g2 library
u8g2.setContrast(200); // set display contrast 0-255
if (! rtc.begin()) // start the RTC module
{
abort();
}
// following line sets the RTC to the date & time this sketch was compiled
// uncomment this when uploading to Arduino, otherwise the time will be 0:00 and not increasing
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop(void)
{
DateTime now = rtc.now(); // get current time
uhr = digitalRead(2);
if ( uhr == 1)
{
char dateAdjust[10] = {'\0'};
char timeAdjust[10] = {'\0'};
sprintf(dateAdjust, "%02d:%02d:%02d", now.day(), now.month(), now.year());
sprintf(timeAdjust, "%02d:%02d:%02d", now.hour() + 1, now.minute(), now.second());
rtc.adjust(DateTime(dateAdjust, timeAdjust));
}
sprintf(time_string, "%02d:%02d", now.hour(), now.minute()); // add hours, colon symbol and minutes into a string
u8g2.setFont(u8g2_font_t0_11b_tn); // choose a suitable font
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(2, 8, time_string); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
delay(1000); // wait one second
}
Ich empfehle eine bessere timelib zu nehmen und dann das ganze stabiler aufzubauen.
bitte poste Code in Code Tags. Wie das geht steht im Forum How To. Du kannst das noch nachträglich in deinem Eingangspost ändern.
now.hour() ist keine Variable die du so setzen kannst. .hour() ist eine member function zum ABFRAGEN.
Schau nach in den Beispielen deiner RTC Library, vermutlich gibt es da eine member function .adjust() mit der du die einzelnen Komponenten deiner Uhrzeit stellen kannst.
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
also kannst du z.B. die Werte die gleich bleiben mit z.B. now.year() auslesen und bei behalten und bei der Stunde deinen neuen Wunsch-Wert einsetzen.
Vielen dank für die schnellen Antworten und Tipps.
Ich dachte" now.hour" wäre eine Variabel so macht das ganze aber sinn ich werde die Tipps umsetzen und dann das ganze nochmal verbessern und ausprobieren
Danke für die TIpps. Ich hab das gerade ausprobiert die Stunden erhöhen sich zwar um jeweils eine Stunde nur leider immer weiter. Beim betätigen des Tasters steigt die Stundenzahl immer weiter und nicht nur um 1.
Gibt es dafür eine einfache Lösung? Es kann aber auch sein das ich einen Hardware Fehler habe.
Ich hab den pinMode vom taster von INPUT auf INPUT_PULLUP geändert.
Funktioniert das?
pinMode(2, INPUT_PULLUP);
pinMode(4, OUTPUT); // we are using pin 4 to power the real time clock module,
digitalWrite(4, HIGH); // since the +5V pin is already used for the display
u8g2.begin(); // begin function is required for u8g2 library
u8g2.setContrast(200); // set display contrast 0-255
if (! rtc.begin()) // start the RTC module
{
abort();
}
// following line sets the RTC to the date & time this sketch was compiled
// uncomment this when uploading to Arduino, otherwise the time will be 0:00 and not increasing
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop(void)
{
DateTime now = rtc.now(); // get current time
uhr = digitalRead(2);
if ( uhr == 0)
{
#include <Arduino.h>
#include <U8g2lib.h>
#include "RTClib.h"
RTC_DS1307 rtc; // set the real time clock module
U8G2_MAX7219_32X8_F_4W_SW_SPI u8g2(U8G2_R0, /* clock=*/ 11, /* data=*/ 12, /* cs=*/ 10, /* dc=*/ U8X8_PIN_NONE, /* reset=*/ U8X8_PIN_NONE);
char time_string[10]; // string to hold the current time to be displayed
const byte adjustPin = 2;
bool adjustMerker = false;;
uint32_t adjustPressTime;
const uint32_t debounceTime = 50;
int lastSecond = 66; // Merker für letzte Sekunde
DateTime now;
void setup(void)
{
pinMode(adjustPin, INPUT_PULLUP);
pinMode(4, OUTPUT); // we are using pin 4 to power the real time clock module,
digitalWrite(4, HIGH); // since the +5V pin is already used for the display
u8g2.begin(); // begin function is required for u8g2 library
u8g2.setContrast(200); // set display contrast 0-255
if (! rtc.begin()) // start the RTC module
{
abort();
}
// following line sets the RTC to the date & time this sketch was compiled
// uncomment this when uploading to Arduino, otherwise the time will be 0:00 and not increasing
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
void loop(void)
{
now = rtc.now(); // get current time
adjustHour();
if (now.second() != lastSecond)
{
lastSecond = now.second();
displayData();
}
}
void adjustHour()
{
if (!digitalRead(adjustPin)) // Taste gedrückt?
{
if (adjustMerker == false) // Vorher nicht gedrückt
{
adjustMerker = true; // Merken dass gedrückt wurde
adjustPressTime = millis(); // Zeit merken wann gedrückt wurde
char dateAdjust[10] = {'\0'};
char timeAdjust[10] = {'\0'};
sprintf(dateAdjust, "%02d:%02d:%02d", now.day(), now.month(), now.year());
sprintf(timeAdjust, "%02d:%02d:%02d", now.hour() + 1, now.minute(), now.second());
rtc.adjust(DateTime(dateAdjust, timeAdjust));
displayData(); // Sofort anzeigen
}
sprintf(time_string, "%02d:%02d", now.hour(), now.minute()); // add hours, colon symbol and minutes into a string
}
else // Taste nicht gedrückt
if (adjustMerker == true) // Aber vorher gedrückt
{
if (millis() - adjustPressTime > debounceTime) // DebounceTime abgelaufen
{
adjustMerker = false; // Merker löschen
}
}
}
void displayData()
{
u8g2.setFont(u8g2_font_t0_11b_tn); // choose a suitable font
u8g2.clearBuffer(); // clear the internal u8g2 memory
u8g2.drawStr(2, 8, time_string); // draw the time string to the display
u8g2.sendBuffer(); // transfer internal memory to the display
}
Das Schaltbild ist schlecht gemacht. Man sieht bei einigen Verbindungen nicht wo sie hinführen.
Die Matrix vom Arduino aus zu versorgen ist definitv falsch.
Davon abgesehen, dass da ein Dislay und keine Matrix dran ist, braucht es nur die Taster um zu sehen, was da passieren soll.
Das ist 2, 3, und 5
Der Rest ist I2C
Zur Versorgung hat er in #8 schon geschrieben, dass das so nicht bleibt.