hallo ich habe versucht eine uhr mit ein dcf77 und eine ws2812b matrix zu bauen nur kriege ich die zeit Synchronisation nicht hin alles andere ist so weit gut
weis jemand was der fehler ist
// Adafruit_NeoMatrix example for single NeoPixel Shield.
#include <DCF77.h>
#include <TimeLib.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
#define PIN 6
#define DCF_PIN 2 // Connection pin to DCF 77 device
#define DCF_INTERRUPT 0 // Interrupt number associated with pin
time_t prevDisplay = 0; // when the digital clock was displayed
time_t time;
DCF77 DCF = DCF77(DCF_PIN, DCF_INTERRUPT);
// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the matrix; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
// rows or in vertical columns, respectively; pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
// in the same order, or alternate lines reverse direction; pick one.
// See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_GRBW Pixels are wired for GRBW bitstream (RGB+W NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(60, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_RGB + NEO_KHZ800);
const uint16_t colors[] = { //G/R/B
matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(255, 255, 0), matrix.Color(0, 255, 255), matrix.Color(0, 0, 255), matrix.Color(255, 0, 255)
};
void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(20);
matrix.setTextColor(colors[0]);
DCF.Start();
setSyncInterval(30);
setSyncProvider(getDCFTime);
pinMode(7, OUTPUT);
pinMode(10, INPUT);
}
int x = matrix.width();
int pass = 0;
int taster = 0;
unsigned long lastUpdateTime = 0;
const unsigned long updateInterval = 100; // Aktualisierungsintervall in Millisekunden
void loop() {
unsigned long currentTime = millis();
if( now() != prevDisplay) //update the display only if the time has changed
{
prevDisplay = now();
}
int stunde = hour();
int minuten = minute();
// Aktualisiere die Zeit und andere Aufgaben nur alle updateInterval Millisekunden
if (currentTime - lastUpdateTime >= updateInterval) {
lastUpdateTime = currentTime;
if ((stunde >= 9 && minuten > 45) && (stunde < 10)) {
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(F("Es ist "));
printDigits(hour());
matrix.print(F(":"));
printDigits(minute());
matrix.print(F(" Uhr "));
matrix.print(F(" Viel Spaß in der Frühstückspause"));
if (--x < -348) { // je zeichen -6(pixel breite)
x = matrix.width();
if (++pass >= 6) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
}
else if ((stunde >= 12) && (stunde <= 12 && minuten < 30)) {
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(F("Es ist "));
printDigits(hour());
matrix.print(F(":"));
printDigits(minute());
matrix.print(F(" Uhr "));
matrix.print(F(" Viel Spaß in der Mittagspause"));
if (x < -324) {
x = matrix.width();
if (++pass >= 6) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
}
else if (stunde == 16 && minuten > 30) {
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(F("Es ist "));
printDigits(hour());
matrix.print(F(":"));
printDigits(minute());
matrix.print(F(" Uhr "));
matrix.print(F(" Schönen Feierabend"));
if (--x < -240) {
x = matrix.width();
if (++pass >= 6) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
}
else {
matrix.fillScreen(0);
matrix.setCursor(4, 0);
printDigits(hour());
matrix.print(F(":"));
printDigits(minute());
matrix.print(F(" Uhr"));
matrix.show();
taster = digitalRead(10);
// Taster gedrückt
if (taster == HIGH) {
// Zur nächsten Farbe wechseln
if (++pass >= 6) pass = 0;
matrix.setTextColor(colors[pass]);
}
}
}
}
void printDigits(int digits) {
// utility function for digital clock display: prints preceding colon and leading 0
if (digits < 10)
matrix.print('0');
matrix.print(digits);
}
unsigned long getDCFTime()
{
time_t DCFtime = DCF.getTime();
// Indicator that a time check is done
if (DCFtime!=0) {
digitalWrite(7, HIGH); // Optional: Indicate successful synchronization
unsigned long currentTime = millis();
if (currentTime - lastUpdateTime >= 500) {
lastUpdateTime = currentTime;
digitalWrite(7, LOW);
}
}
return DCFtime;
}