Retro horloge met ESP, RTC en LED-matrix

Hallo,

de horloges we hadden al in ons Blog, of een radio klok of de NTP-Protocol, met Display , of onze U64 Paneel. Vandaag wil ik u voorstellen aan een variant met ESP, de RTC en de LED-Matrix. Vriendelijk mij gegeven heeft een jongere collega op het feit dat dit soort horloges zijn al lang achterhaald en bewust gemaakt die ik nu heb.... nou, niet in, zeg, de telling van de jongere hobbyisten, en vroeg me "aan de Retro" in de titel.

Voor ons project hebben we nodig:

in Dit project hebben we op GitHub te vinden hier voor onze doeleinden.

Voordat we beginnen, raad ik aan om de tijd in de RTC met een Arduino, omdat dit kan leiden tot de ESPs soms problemen. We hebben in onze gratis E-Boek voor de RTC in detail uitgelegd.

Dit project als zeer goed, omdat de datum is angeizeigt en het effect van het veranderen van de tijd was van een zeer hoge kwaliteit.

Bedrading:

Amica LED Matrix RTC DS3231
D1 SDA
D2 SCL -
D5 CLK -
D7 DIN
D8 CS
VIN VCC
GND GND GND
3.3 V VCC

 

Hier is de Code:

 

//*********************************************************************************************************
//* ESP8266 matrix clock *
//*********************************************************************************************************
//
// eerste release op 26.02.2017
// bijgewerkt op 26.03.2019
// Versie 1.2.1
//
//
// DE SOFTWARE WORDT GELEVERD "ZOALS het IS" ALLEEN VOOR PERSOONLIJK GEBRUIK, HET IS NIET VOOR COMMERCIEEL GEBRUIK IN ZIJN GEHEEL OF EEN GEDEELTE OF EEN CONCEPT.
// VOOR PERSOONLIJK GEBRUIK IS GELEVERD, ZONDER ENIGE GARANTIE, UITDRUKKELIJK OF IMPLICIET, MET INBEGRIP VAN MAAR NIET BEPERKT TOT DE
// GARANTIES VAN VERKOOPBAARHEID, GESCHIKTHEID VOOR EEN BEPAALD DOEL EN NIET-INBREUK. IN GEEN GEVAL ZAL DE AUTEUR
/ OF COPYRIGHT HOUDER AANSPRAKELIJK VOOR ENIGE CLAIM, SCHADE OF ANDERE AANSPRAKELIJKHEID, HETZIJ IN CONTRACT, ONRECHTMATIGE DAAD OF
// ANDERSZINS, VOORTVLOEIEND UIT, UIT OF IN VERBAND MET DE SOFTWARE OF HET GEBRUIK van OF ANDERE RELATIES tot DE SOFTWARE
//Gemaakt van https://github.com/schreibfaul1/ESP8266-LED-Matrix-Clock
//Bewerkt door AZ-Levering

#include <SPI.h>
#include <Ticker.h>
#include <ESP8266WiFi.h>
#include <Draad.h>
#include <tijd.h>

#define SDA        5      // Pin sda (I2C)
#define SCL        4      // Pin scl (I2C)
#define CS         15     // Pin-cs (SPI)
#define anzMAX     4      // aantal cascade modules


unsigned short maxPosX = anzMAX * 8 - 1;            //berekend maxposition
unsigned short LEDarr[anzMAX][8];                   //het teken matrix display (40*8)
unsigned short helpArrMAX[anzMAX * 8];              //help array van char decoderen
unsigned short helpArrPos[anzMAX * 8];              //help array pos van char decoderen
unsigned int z_PosX = 0;                            //blootstelling in de Display voor de weergave van de tijd,
unsigned int d_PosX = 0;                            //blootstelling in de f-Display investerin-r datum display
bool f_tckr1s = valse;
bool f_tckr50ms = valse;
bool f_tckr24h = valse;
unsigned long tijdperk = 0;


//Variabelen voor de RTC DS3231
const unsigned char DS3231_ADDRESS = 0x68;
const unsigned char secondREG = 0x00;
const unsigned char minuteREG = 0x01;
const unsigned char hourREG = 0x02;
const unsigned char WTREG = 0x03;                   //weekdag
const unsigned char dateREG = 0x04;
const unsigned char monthREG = 0x05;
const unsigned char yearREG = 0x06;
const unsigned char alarm_min1secREG = 0x07;
const unsigned char alarm_min1minREG = 0x08;
const unsigned char alarm_min1hrREG = 0x09;
const unsigned char alarm_min1dateREG = 0x0A;
const unsigned char alarm_min2minREG = 0x0B;
const unsigned char alarm_min2hrREG = 0x0C;
const unsigned char alarm_min2dateREG = 0x0D;
const unsigned char controlREG = 0x0E;
const unsigned char statusREG = 0x0F;
const unsigned char ageoffsetREG = 0x10;
const unsigned char tempMSBREG = 0x11;
const unsigned char tempLSBREG = 0x12;
const unsigned char _24_hour_format = 0;
const unsigned char _12_hour_format = 1;
const unsigned char in DE = 0;
const unsigned char UUR = 1;

struct DateTime {     unsigned short sek1, sek2, sek12, min1, min2, min12, std1, std2, std12;     unsigned short tag1, tag2, tag12, mon1, mon2, mon12, jahr1, jahr2, jahr12, WT;
} BEPERKEN;


// De object voor de Lichtkrant
Lichtkrant tckr;



//maanden
char M_arr[12][5] = { { '.', 'J', 'a', 'n', '.' }, { '.', 'F', 'e', 'b', '.' },         { '.', 'M', 'en', 'r', '.' }, { '.', 'A', 'p', 'r', '.' }, { '.', 'M', 'a',                 'y', ' ' }, { '.', 'J', 'u', 'n', 'e' }, { '.', 'J', 'u', 'l', 'y' }, {                 '.', 'A', 'u', 'g', '.' }, { '.', 'S', 'e', 'p', 't' }, { '.', 'O', 'c',                 't', '.' }, { '.', 'N', 'o', 'v', '.' }, { '.', 'D', 'e', 'c'', '.' } };
//dagen
char WT_arr[7][4] = { { 'S', 'u', 'n', ',' }, { 'M', 'o', 'n', ',' }, { 'T', 'u', 'e', ',' }, {         'D', 'e', 'd', ',' }, { 'T', 'h', 'u', ',' }, { 'F', 'r', 'i', ',' }, { 'S', 'a', 't', ',' } };

// Zeichensatz 5x8 in einer 8x8 Matrix, 0,0 ist rechts oben
unsigned short const font1[96][9] = { { 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,         0x00, 0x00, 0x00 },   // 0x20, Ruimte         { 0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x04, 0x00 },   // 0x21, !         { 0x07, 0x09, 0x09, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00 },   // 0x22, "         { 0x07, 0x0a, 0x0a, x 0x1f, 0x0a, x 0x1f, 0x0a, 0x0a, 0x00 },   // 0x23, #         { 0x07, 0x04, 0x0f, 0x14, 0x0e, 0x05, 0x1e, 0x04, 0x00 },   // 0x24, $         { 0x07, 0x19, 0x19, 0x02, 0x04, 0x08, 0x13, 0x13, 0x00 },   // 0x25, %         { 0x07, 0x04, 0x0a, 0x0a, 0x0a, 0x15, 0x12, 0x0d, 0x00 },   // 0x26, &         { 0x07, 0x04, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },   // 0x27, '         { 0x07, 0x02, 0x04, 0x08, 0x08, 0x08, 0x04, 0x02, 0x00 },   // 0x28, (         { 0x07, 0x08, 0x04, 0x02, 0x02, 0x02, 0x04, 0x08, 0x00 },   // 0x29, )         { 0x07, 0x04, 0x15, 0x0e, x 0x1f, 0x0e, 0x15, 0x04,, 0x00, },   // 0x2a, *         { 0x07, 0x00, 0x04, 0x04, x 0x1f, 0x04, 0x04, 0x00, 0x00 },   // 0x2b, +         { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02 },   // 0x2c, ,         { 0x07, 0x00, 0x00, 0x00, x 0x1f, 0x00, 0x00, 0x00, 0x00 },   // 0x2d, -         { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00 },   // 0x2e, .         { 0x07, 0x01, 0x01, 0x02, 0x04, 0x08, 0x10, 0x10, 0x00 },   // 0x2f, /         { 0x07, 0x0e, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0e, 0x00, },   // 0x30, 0         { 0x07, 0x04, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x0e, 0x00, },   // 0x31, 1         { 0x07, 0x0e, 0x11, 0x01, 0x02, 0x04, 0x08, x 0x1f, 0x00 },   // 0x32, 2         { 0x07, 0x0e, 0x11, 0x01, 0x06, 0x01, 0x11, 0x0e, 0x00, },   // 0x33, 3         { 0x07, 0x02, 0x06, 0x0a, 0x12, x 0x1f, 0x02, 0x02, 0x00 },   // 0x34, 4         { 0x07, x 0x1f, 0x10, 0x1e, 0x01, 0x01, 0x11, 0x0e, 0x00, },   // 0x35, 5         { 0x07, 0x06, 0x08, 0x10, 0x1e, 0x11, 0x11, 0x0e, 0x00, },   // 0x36, 6         { 0x07, x 0x1f, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08, 0x00, },   // 0x37, 7         { 0x07, 0x0e, 0x11, 0x11, 0x0e, 0x11, 0x11, 0x0e, 0x00, },   // 0x38, 8         { 0x07, 0x0e, 0x11, 0x11, 0x0f, 0x01, 0x02, 0x0c, 0x00, },   // 0x39, 9         { 0x04, 0x00, 0x03, 0x03, 0x00, 0x03, 0x03, 0x00, 0x00, },   // 0x3a, :         { 0x07, 0x00, 0x0c, 0x0c, 0x00, 0x0c, 0x04, 0x08, 0x00, },   // 0x3b, ;         { 0x07, 0x02, 0x04, 0x08, 0x10, 0x08, 0x04, 0x02, 0x00 },   // 0x3c, <         { 0x07, 0x00, 0x00, x 0x1f, 0x00, x 0x1f, 0x00, 0x00, 0x00 },   // 0x3d, =         { 0x07, 0x08, 0x04, 0x02, 0x01, 0x02, 0x04, 0x08, 0x00, },   // 0x3e, >         { 0x07, 0x0e, 0x11, 0x01, 0x02, 0x04, 0x00, 0x04, 0x00 },   // 0x3f, ?         { 0x07, 0x0e, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0f, 0x00, },   // 0x40, @         { 0x07, 0x04, 0x0a, 0x11, 0x11, x 0x1f, 0x11, 0x11, 0x00 },   // 0x41,         { 0x07, 0x1e, 0x11, 0x11, 0x1e, 0x11, 0x11, 0x1e, 0x00 },   // 0x42, B         { 0x07, 0x0e, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0e, 0x00 },   // 0x43, C         { 0x07, 0x1e, 0x09, 0x09, 0x09, 0x09, 0x09, 0x1e, 0x00 },   // 0x44, D         { 0x07, x 0x1f, 0x10, 0x10, 0x1c, 0x10, 0x10, x 0x1f, 0x00 },   // 0x45, E         { 0x07, x 0x1f, 0x10, 0x10, x 0x1f, 0x10, 0x10, 0x10, 0x00 },   // 0x46, F         { 0x07, 0x0e, 0x11, 0x10, 0x10, 0x13, 0x11, 0x0f, 0x00 },   // 0x37,         { 0x07, 0x11, 0x11, 0x11, x 0x1f, 0x11, 0x11, 0x11, 0x00 },   // 0x48, H         { 0x07, 0x0e, 0x04, 0x04, 0x04, 0x04, 0x04, 0x0e, 0x00 },   // 0x49, ik         { 0x07, x 0x1f, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0c, 0x00 },   // 0x4a, J         { 0x07, 0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11, 0x00 },   // 0x4b, K         { 0x07, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, x 0x1f, 0x00 },   // 0x4c, De         { 0x07, 0x11, 0x1b, 0x15, 0x11, 0x11, 0x11, 0x11, 0x00 },   // 0x4d, M         { 0x07, 0x11, 0x11, 0x19, 0x15, 0x13, 0x11, 0x11, 0x00 },   // 0x4e, N         { 0x07, 0x0e, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00 },   // 0x4f, O         { 0x07, 0x1e, 0x11, 0x11, 0x1e, 0x10, 0x10, 0x10, 0x00 },   // 0x50, P         { 0x07, 0x0e, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0d, 0x00 },   // 0x51, Q         { 0x07, 0x1e, 0x11, 0x11, 0x1e, 0x14, 0x12, 0x11, 0x00 },   // 0x52,         { 0x07, 0x0e, 0x11, 0x10, 0x0e, 0x01, 0x11, 0x0e, 0x00 },   // 0x53,         { 0x07, x 0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00 },   // 0x54, De         { 0x07, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0e, 0x00 },   // 0x55,         { 0x07, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0a, 0x04, 0x00 },   // 0x56, V         { 0x07, 0x11, 0x11, 0x11, 0x15, 0x15, 0x1b, 0x11, 0x00 },   // 0x57, W         { 0x07, 0x11, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x11, 0x00 },   // 0x58, X         { 0x07, 0x11, 0x11, 0x0a, 0x04, 0x04, 0x04, 0x04, 0x00 },   // 0x59, Y         { 0x07, x 0x1f, 0x01, 0x02, 0x04, 0x08, 0x10, x 0x1f, 0x00 },   // 0x5a, Z         { 0x07, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0e, 0x00 },   // 0x5b, [         { 0x07, 0x10, 0x10, 0x08, 0x04, 0x02, 0x01, 0x01, 0x00 },   // 0x5c, '\A         { 0x07, 0x0e, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0e, 0x00 },   // 0x5d, ]         { 0x07, 0x04, 0x0a, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00 },   // 0x5e, ^         { 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, x 0x1f, 0x00 },   // 0x5f, _         { 0x07, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 },   // 0x60, `         { 0x07, 0x00, 0x0e, 0x01, 0x0d, 0x13, 0x13, 0x0d, 0x00 },   // 0x61, een         { 0x07, 0x10, 0x10, 0x10, 0x1c, 0x12, 0x12, 0x1c, 0x00 },   // 0x62, b         { 0x07, 0x00, 0x00, 0x00, 0x0e, 0x10, 0x10, 0x0e, 0x00 },   // 0x63, c         { 0x07, 0x01, 0x01, 0x01, 0x07, 0x09, 0x09, 0x07, 0x00 },   // 0x64, d         { 0x07, 0x00, 0x00, 0x0e, 0x11, x 0x1f, 0x10, 0x0f, 0x00 },   // 0x65, e         { 0x07, 0x06, 0x09, 0x08, 0x1c, 0x08, 0x08, 0x08, 0x00 },   // 0x66, f         { 0x07, 0x00, 0x0e, 0x11, 0x13, 0x0d, 0x01, 0x01, 0x0e },   // 0x67, g         { 0x07, 0x10, 0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x00 },   // 0x68, h         { 0x05, 0x00, 0x02, 0x00, 0x06, 0x02, 0x02, 0x07, 0x00 },   // 0x69, ik         { 0x07, 0x00, 0x02, 0x00, 0x06, 0x02, 0x02, 0x12, 0x0c },   // 0x6a, j         { 0x07, 0x10, 0x10, 0x12, 0x14, 0x18, 0x14, 0x12, 0x00 },   // 0x6b, k         { 0x05, 0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00 },   // 0x6c,         { 0x07, 0x00, 0x00, 0x0a, 0x15, 0x15, 0x11, 0x11, 0x00 },   // 0x6d, m         { 0x07, 0x00, 0x00, 0x16, 0x19, 0x11, 0x11, 0x11, 0x00 },   // 0x6e, n         { 0x07, 0x00, 0x00, 0x0e, 0x11, 0x11, 0x11, 0x0e, 0x00 },   // 0x6f, o         { 0x07, 0x00, 0x00, 0x1c, 0x12, 0x12, 0x1c, 0x10, 0x10 },   // 0x70, p         { 0x07, 0x00, 0x00, 0x07, 0x09, 0x09, 0x07, 0x01, 0x01 },   // 0x71, q         { 0x07, 0x00, 0x00, 0x16, 0x19, 0x10, 0x10, 0x10, 0x00 },   // 0x72, r         { 0x07, 0x00, 0x00, 0x0f, 0x10, 0x0e, 0x01, 0x1e, 0x00 },   // 0x73, s         { 0x07, 0x08, 0x08, 0x1c, 0x08, 0x08, 0x09, 0x06, 0x00 },   // 0x74,         { 0x07, 0x00, 0x00, 0x11, 0x11, 0x11, 0x13, 0x0d, 0x00 },   // 0x75,         { 0x07, 0x00, 0x00, 0x11, 0x11, 0x11, 0x0a, 0x04, 0x00 },   // 0x76, v         { 0x07, 0x00, 0x00, 0x11, 0x11, 0x15, 0x15, 0x0a, 0x00 },   // 0x77, w         { 0x07, 0x00, 0x00, 0x11, 0x0a, 0x04, 0x0a, 0x11, 0x00 },   // 0x78, x         { 0x07, 0x00, 0x00, 0x11, 0x11, 0x0f, 0x01, 0x11, 0x0e },   // 0x79, y         { 0x07, 0x00, 0x00, x 0x1f, 0x02, 0x04, 0x08, x 0x1f, 0x00 },   // 0x7a, z         { 0x07, 0x06, 0x08, 0x08, 0x10, 0x08, 0x08, 0x06, 0x00 },   // 0x7b, {         { 0x07, 0x04, 0x04, 0x04, 0x00, 0x04, 0x04, 0x04, 0x00 },   // 0x7c, |         { 0x07, 0x0c, 0x02, 0x02, 0x01, 0x02, 0x02, 0x0c, 0x00 },   // 0x7d, }         { 0x07, 0x08, 0x15, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 },   // 0x7e, ~         { 0x07, x 0x1f, x 0x1f, x 0x1f, x 0x1f, x 0x1f, x 0x1f, x 0x1f, 0x00 }    // 0x7f DEL
};
//**************************************************************************************************

//**************************************************************************************************
void rtc_init(unsigned char sda, unsigned char scl) {     Draad.beginnen(sda, scl);     rtc_Write(controlREG, 0x00);
}
//**************************************************************************************************
// BCD-Code
//**************************************************************************************************
unsigned char dec2bcd(unsigned char x) { //waarde 0...99     unsigned char z, e, r;     e = x % 10;     z = x / 10;     z = z << 4;     r = e | z;     terugkeer van (de);
}
unsigned char bcd2dec(unsigned char x) { //waarde 0...99     u bent een z, e;     e = x & 0x0F;     z = x & 0xF0;     z = z >> 4;     z = z * 10;     return (z + e);
}
//**************************************************************************************************
// RTC I2C Code
//**************************************************************************************************
unsigned char rtc_Read(unsigned char regaddress) {     Draad.beginTransmission(DS3231_ADDRESS);     Draad.schrijven(regaddress);     Draad.endTransmission();     Draad.requestFrom((unsigned char) DS3231_ADDRESS, (unsigned char) 1);     terug (de Draad.lees());
}
void rtc_Write(unsigned char regaddress, unsigned char waarde) {     Draad.beginTransmission(DS3231_ADDRESS);     Draad.schrijven(regaddress);     Draad.schrijven(waarde);     Draad.endTransmission();
}
//**************************************************************************************************
unsigned char rtc_sekunde() {     terug (bcd2dec(rtc_Read(secondREG)));
}
unsigned char rtc_minute() {     terug (bcd2dec(rtc_Read(minuteREG)));
}
unsigned char rtc_stunde() {     terug (bcd2dec(rtc_Read(hourREG)));
}
unsigned char rtc_wochentag() {     terug (bcd2dec(rtc_Read(WTREG)));
}
unsigned char rtc_tag() {     terug (bcd2dec(rtc_Read(dateREG)));
}
unsigned char rtc_monat() {     terug (bcd2dec(rtc_Read(monthREG)));
}
unsigned char rtc_jahr() {     terug (bcd2dec(rtc_Read(yearREG)));
}
void rtc_sekunde(unsigned char sec) {     rtc_Write(secondREG, (dec2bcd(sek)));
}
void rtc_minute(unsigned char min) {     rtc_Write(minuteREG, (dec2bcd(op)));
}
nietig rtc_stunde(unsigned char std) {     rtc_Write(hourREG, (dec2bcd(std)));
}
void rtc_wochentag(unsigned char wt) {     rtc_Write(WTREG, (dec2bcd(wt)));
}
void rtc_tag(unsigned char tag) {     rtc_Write(dateREG, (dec2bcd(tag)));
}
void rtc_monat(unsigned char mon) {     rtc_Write(monthREG, (dec2bcd(mon)));
}
void rtc_jahr(unsigned char jahr) {     rtc_Write(yearREG, (dec2bcd(jahr)));
}
//**************************************************************************************************
void rtc_set(tm* tt) {     rtc_sekunde((unsigned char) tt->tm_sec);     rtc_minute((unsigned char) tt->tm_min);     rtc_stunde((unsigned char) tt->tm_hour);     rtc_tag((unsigned char) tt->tm_mday);     rtc_monat((unsigned char) tt->tm_mon + 1);     rtc_jahr((unsigned char) tt->tm_year - 100);     rtc_wochentag((unsigned char) tt->tm_wday);
}
//**************************************************************************************************
float rtc_temp() {     float t = 0.0;     unsigned char low-bytes = 0;     signed char bytes = 0;     low-bytes = rtc_Read(tempLSBREG);     bytes = rtc_Read(tempMSBREG);     low-bytes >>= 6;     low-bytes &= 0x03;     t = ((float) low-bytes);     t *= 0.25;     t += bytes;     terug (t); // return temp waarde
}
//**************************************************************************************************
void rtc2mez() {     unsigned short JaZiff;       //Jahresziffer     unsigned short JhZiff = 6;   //Jahrhundertziffer für 20.Jahrhundert     unsigned short TaZiff;       //Tagesziffer     unsigned short WoTag;        //Wochentag     unsigned short SJK = 0;      //Schaltjahreskorrektur     unsigned short ZDiff;        //Zeitdifferenz UTC MEZ/MESZ     unsigned short MoZiff[12] = { 0, 3, 3, 6, 1, 4, 6, 2, 5, 0, 3, 5 }; //Monatsziffer     unsigned short Tage_Monat[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,             31 };     unsigned short Jahr, Tag, Monat, Stunde, Minuten, Sekunde;     //RTC_setMonat(3);     Jahr = rtc_jahr();     als (Jahr > 99)         Jahr = 0;     Monat = rtc_monat();     als (Monat > 12)         Monat = 0;     Tag = rtc_tag();     als (Tag > 31)         Tag = 0;     Stunde = rtc_stunde();     als (Stunde > 23)         Stunde = 0;     Minuten = rtc_minute();     indien (Minuten > 59)         Minuten = 0;     Sekunde = rtc_sekunde();     als (Sekunde > 59)         Sekunde = 0;     JaZiff = ((Jahr + Jahr / 4) % 7);     TaZiff = (Tag % 7);     als ((Jahr % 4) == 0)                          //Schaltjahr ?     {         Tage_Monat[1] = 29;                      //dann hat der Febr 29 Tage         als (Monat < 3)             SJK = 6;         anders             SJK = 0;     }     WoTag = ((TaZiff + MoZiff[Monat - 1] + JhZiff + JaZiff + SJK) % 7);     als (Monat < 3 || Monat > 10)         ZDiff = 1; // keine Sommerzeit in Jan, Feb, Nov, Dec     als (Monat > 3 && Monat < 10)         ZDiff = 2; // Sommerz. in April, Mei, Jun, Jul, Aug, Sep     als (Monat == 3) {         ZDiff = 1;         als (Tag > 24)     //Sommerzeit ab letzten Sonntag des Monats         {             als (Tag == 25) {                 als ((Tag + WoTag) < 26)                     ZDiff = 2;             }             als (Tag == 26) {                 als ((Tag + WoTag) < 28)                     ZDiff = 2;             }             als (Tag == 27) {                 als ((Tag + WoTag) < 30)                     ZDiff = 2;             }             als (Tag == 28) {                 als ((Tag + WoTag) < 32)                     ZDiff = 2;             }             als (Tag == 29) {                 als ((Tag + WoTag) < 34)                     ZDiff = 2;             }             als (Tag == 30) {                 als ((Tag + WoTag) < 36)                     ZDiff = 2;             }             als (Tag == 31) {                 als ((Tag + WoTag) < 38)                     ZDiff = 2;             }             als ((ZDiff == 2) && (Stunde + 1 < 2) && (WoTag == 0))                 ZDiff = 1; //erst ab 02 Uhr         }     }     als (Monat == 10) {         ZDiff = 2;         als (Tag > 24)     //Sommerzeit ab letzten Sonntag des Monats         {             als (Tag == 25) {                 als ((Tag + WoTag) < 26)                     ZDiff = 1;             }             als (Tag == 26) {                 als ((Tag + WoTag) < 28)                     ZDiff = 1;             }             als (Tag == 27) {                 als ((Tag + WoTag) < 30)                     ZDiff = 1;             }             als (Tag == 28) {                 als ((Tag + WoTag) < 32)                     ZDiff = 1;             }             als (Tag == 29) {                 als ((Tag + WoTag) < 34)                     ZDiff = 1;             }             als (Tag == 30) {                 als ((Tag + WoTag) < 36)                     ZDiff = 1;             }             als (Tag == 31) {                 als ((Tag + WoTag) < 38)                     ZDiff = 1;             }             als ((ZDiff == 1) && (Stunde == 0) && (WoTag == 0))                 ZDiff = 2; //erst ab 02 Uhr         }     }     Stunde = Stunde + ZDiff;     als (Stunde > 23)       //Tageskorrektur     {         Stunde = Stunde - 24; //kann 0 of 1 sein         - Tag = Tag + 1;         WoTag = WoTag + 1;         als (Tag > Tage_Monat[Monat - 1]) {             Tag = 1;             Monat = Monat + 1;             als (Monat > 12) {                 Monat = 1;                 Jahr = Jahr + 1;             }         }     }     MEZ.WT = WoTag;          //So=0, Mo=1, Di=2 ...     MEZ.sek1 = Sekunde % 10;     MEZ.sek2 = Sekunde / 10;     MEZ.sek12 = Sekunde;     MEZ.min1 = Minuten % 10;     MEZ.min2 = Minuten / 10;     MEZ.min12 = Minuten;     MEZ.std1 = Stunde % 10;     MEZ.std2 = Stunde / 10;     MEZ.std12 = Stunde;     MEZ.tag12 = Tag;     MEZ.tag1 = Tag % 10;     MEZ.tag2 = Tag / 10;     MEZ.mon12 = Monat;     MEZ.mon1 = Monat % 10;     MEZ.mon2 = Monat / 10;     MEZ.jahr12 = Jahr;     MEZ.jahr1 = Jahr % 10;     MEZ.jahr2 = Jahr / 10;
}

//*************************************************************************************************
const unsigned short InitArr[7][2] = { { 0x0C, 0x00 },    // display uit         { 0x00, 0xFF },    // geen LEDtest         { 0x09, 0x00 },    // BCD uit         { 0x0F, 0x00 },    // normale werking         { 0x0B, 0x07 },    // start weergeven         { 0x0A, 0x04 },    // helderheid         { 0x0C, 0x01 }     // scherm op
};
//**************************************************************************************************
nietig max7219_init()  //alle MAX7219 init
{     unsigned short i, j;     voor (i = 0; i < 7; i++) {         digitalWrite(CS, LAGE);         delayMicroseconds(1);         voor (j = 0; j < anzMAX; j++) {             SPI.schrijven(InitArr[ik][0]);  //register             SPI.schrijven(InitArr[ik][1]);  //waarde         }         digitalWrite(CS, HOGE);     }
}
//**************************************************************************************************
void max7219_set_brightness(unsigned short br)  //helderheid MAX7219
{     unsigned short j;     als (br < 16) {         digitalWrite(CS, LAGE);         delayMicroseconds(1);         voor (j = 0; j < anzMAX; j++) {             SPI.schrijven(0x0A);  //register             SPI.schrijven(br);    //waarde         }         digitalWrite(CS, HOGE);     }
}
//**************************************************************************************************
void helpArr_init(void)  //helperarray init
{     unsigned short i, j, k;     j = 0;     k = 0;     voor (i = 0; i < anzMAX * 8; ik++) {         helpArrPos[i] = (1 << j);   //bitmask         helpArrMAX[i] = k;         j++;         als (j > 7) {             j = 0;             k++;         }     }
}
//**************************************************************************************************
void clear_Display()   //wis alle
{     niet-ondertekende korte i, j;     voor (i = 0; i < 8; i++)     //8 rijen     {         digitalWrite(CS, LAGE);         delayMicroseconds(1);         voor (j = anzMAX; j > 0; j--) {             LEDarr[j - 1][i] = 0;       //LEDarr duidelijk             SPI.schrijf(ik + 1);           //huidige rij             SPI.schrijven(LEDarr[j - 1][ik]);         }         digitalWrite(CS, HOGE);     }
}
//*********************************************************************************************************
void rotate_90() // voor Generieke geeft
{     voor (uint8_t k = anzMAX; k > 0; k--) {         uint8_t i, j, m, imask, jmask;         uint8_t tmp[8]={0,0,0,0,0,0,0,0};         voor (  ik = 0, imask = 0x01; ik < 8; ik++, imask <<= 1) {           voor (j = 0, jmask = 0x01; j < 8; j++, jmask <<= 1) {             als (LEDarr[k-1][i] & jmask) {               tmp[j] |= imask;             }           }         }         voor(m=0; m<8; m++){             LEDarr[k-1][m]=tmp[m];         }     }
}
//**************************************************************************************************
void refresh_display() //neem de info in LEDarr
{     unsigned short i, j;

#ifdef ROTATE_90     rotate_90();
#endif     voor (i = 0; i < 8; i++)     //8 rijen     {         digitalWrite(CS, LAGE);         delayMicroseconds(1);         voor (j = anzMAX; j > 0; j--) {             SPI.schrijf(ik + 1);  //huidige rij

#ifdef REVERSE_HORIZONTAL             SPI.setBitOrder(LSBFIRST);      // bitorder voor reverse kolommen
#endif

#ifdef REVERSE_VERTICAL             SPI.schrijven(LEDarr[j - 1][7-i]);
#anders             SPI.schrijven(LEDarr[j - 1][i]);
#endif

#ifdef REVERSE_HORIZONTAL             SPI.setBitOrder(MSBFIRST);      // reset bitorder
#endif         }         digitalWrite(CS, HOGE);     }
}
//**************************************************************************************************
void char2Arr(unsigned short ch, int PosX, korte PosY) { //tekens in arr     int i, j, k, l, m, o1, o2, o3, o4;  //in LEDarr     PosX++;     k = ch - 32;                        //ASCII-positie in het lettertype     als ((k >= 0) && (k < 96))           /teken/, gevonden in het lettertype?     {         o4 = font1[k)][0];                 //breedte (tekens)         o3 = 1 << (o4 - 2);         voor (ik = 0; ik < o4; ik++) {             als (((PosX - ik <= maxPosX) && (PosX - ik >= 0))                     && ((PosY > -8) && (PosY < 8))) //in de matrix?             {                 a1 = helpArrPos[PosX - ik];                 o2 = helpArrMAX[PosX - ik];                 voor (j = 0; j < 8; j++) {                     indien (((PosY >= 0) && (PosY <= j)) || ((PosY < 0) && (j < PosY + 8))) //verticaal schuiven                     {                         l = font1[k][j + 1];                         m = (l & (o3 >> ik));  //bijv. o4=7 0zzzzz0, o4=4 0zz0                         als (m > 0)                             LEDarr[o2][j - PosY] = LEDarr[o2][j - PosY] | (o1);  //instelpunt                         anders                             LEDarr[o2][j - PosY] = LEDarr[o2][j - PosY] & (~o1); //duidelijk punt                     }                 }             }         }     }
}

//**************************************************************************************************
nietig timer50ms() {     statische unsigned int cnt50ms = 0;     statische unsigned int cnt1s = 0;     statische unsigned int cnt1h = 0;     f_tckr50ms = ware;     cnt50ms++;     als (cnt50ms == 20) {         f_tckr1s = true; // 1 sec         cnt1s++;         cnt50ms = 0;     }     als (cnt1s == 3600) { // 1h         cnt1h++;         cnt1s = 0;     }     als (cnt1h == 24) { // 1d         f_tckr24h = ware;         cnt1h = 0;     }
}
//**************************************************************************************************
//
//De setup-functie wordt aangeroepen bij het opstarten van de schets
void setup() {     // Voeg uw initialisatie code hier        pinMode(CS, UITGANG);     digitalWrite(CS, HOGE);     Seriële.beginnen(115200);     //rtc.init(SDA, SCL);     SPI.beginnen();     helpArr_init();     max7219_init();     rtc_init(SDA, SCL);     clear_Display();     tckr.hechten(0.05, timer50ms);    // elke 50 msec     tm* tt;     als (tt != NULL)         rtc_set(tt);     anders         Seriële.println("geen timepacket ontvangen");
}
//**************************************************************************************************
// De loop-functie wordt aangeroepen in een eindeloze lus
void loop() {     //Het toevoegen van uw herhaalde code hier     unsigned int sek1 = 0, sek2 = 0, min1 = 0, min2 = 0, std1 = 0, std2 = 0;     unsigned int sek11 = 0, sek12 = 0, sek21 = 0, sek22 = 0;     unsigned int min11 = 0, min12 = 0, min21 = 0, min22 = 0;     unsigned int std11 = 0, std12 = 0, std21 = 0, std22 = 0;     signed int x = 0; /x1,x2;     signed int y = 0, y1 = 0, y2 = 0;     bool updown = valse;     unsigned int sc1 = 0, sc2 = 0, sc3 = 0, sc4 = 0, sc5 = 0, sc6 = 0;     bool f_scrollend_y = valse;     unsigned int f_scroll_x = valse;     z_PosX = maxPosX;     d_PosX = -8;     // x=0; x1=0; x2=0;     refresh_display();     updown = ware;     als (updown == valse) {         y2 = -9;         y1 = 8;     }     als (updown == true) { //druk de navigatietoets omhoog om omlaag         y2 = 8;         y1 = -8;     }     , terwijl het (werkelijke) {         rendement();         als (f_tckr24h == true) { //syncronisize RTC elke dag             f_tckr24h = valse;             tm* tt;             als (tt != NULL)                 rtc_set(tt);             anders                 Seriële.println("geen timepacket ontvangen");         }         als (f_tckr1s == true)        // vlag 1sek         {             rtc2mez();             sek1 = MEZ.sek1;             sek2 = MEZ.sek2;             min1 = MEZ.min1;             min2 = MEZ.min2;             std1 = MEZ.std1;             std2 = MEZ.std2;             y = y2;                 //ga updown             sc1 = 1;             sek1++;             als (sek1 == 10) {                 sc2 = 1;                 sek2++;                 sek1 = 0;             }             als (sek2 == 6) {                 min1++;                 sek2 = 0;                 sc3 = 1;             }             als (min1 == 10) {                 min2++;                 min1 = 0;                 sc4 = 1;             }             als (min2 == 6) {                 std1++;                 min2 = 0;                 sc5 = 1;             }             als (std1 == 10) {                 std2++;                 std1 = 0;                 sc6 = 1;             }             als ((std2 == 2) && (std1 == 4)) {                 std1 = 0;                 std2 = 0;                 sc6 = 1;             }             sek11 = sek12;             sek12 = sek1;             sek21 = sek22;             sek22 = sek2;             min11 = min12;             min12 = min1;             min21 = min22;             min22 = min2;             std11 = std12;             std12 = std1;             std21 = std22;             std22 = std2;             f_tckr1s = false;             als (MEZ.sek12 == 45)                 f_scroll_x = true;         } // einde 1s         als (f_tckr50ms == ware) {             f_tckr50ms = false;             als (f_scroll_x == ware) {                 z_PosX++;                 d_PosX++;                 als (d_PosX == 101)                     z_PosX = 0;                 als (z_PosX == maxPosX) {                     f_scroll_x = valse;                     d_PosX = -8;                 }             }             als (sc1 == 1) {                 als (updown == 1)                     y--;                 else                     y++;                 char2Arr(48 + sek12, z_PosX - 42, y);                 char2Arr(48 + sek11, z_PosX - 42, y + y1);                 als (y == 0) {                     sc1 = 0;                     f_scrollend_y = waar;                 }             }             anders                 char2Arr(48 + sek1, z_PosX - 42, 0);             als (sc2 == 1) {                 char2Arr(48 + sek22, z_PosX - 36, y);                 char2Arr(48 + sek21, z_PosX - 36, y + y1);                 als (y == 0)                     sc2 = 0;             }             anders                 char2Arr(48 + sek2, z_PosX - 36, 0);             char2Arr(':', z_PosX - 32, 0);             als (sc3 == 1) {                 char2Arr(48 + min12, z_PosX - 25, y);                 char2Arr(48 + min11, z_PosX - 25, y + y1);                 als (y == 0)                     sc3 = 0;             }             anders                 char2Arr(48 + min1, z_PosX - 25, 0);             als (sc4 == 1) {                 char2Arr(48 + min22, z_PosX - 19, y);                 char2Arr(48 + min21, z_PosX - 19, y + y1);                 als (y == 0)                     sc4 = 0;             }             anders                 char2Arr(48 + min2, z_PosX - 19, 0);             char2Arr(':', z_PosX - 15 + x, 0);             als (sc5 == 1) {                 char2Arr(48 + std12, z_PosX - 8, y);                 char2Arr(48 + std11, z_PosX - 8, y + y1);                 als (y == 0)                     sc5 = 0;             }             anders                 char2Arr(48 + std1, z_PosX - 8, 0);             als (sc6 == 1) {                 char2Arr(48 + std22, z_PosX - 2, y);                 char2Arr(48 + std21, z_PosX - 2, y + y1);                 als (y == 0)                     sc6 = 0;             }             anders                 char2Arr(48 + std2, z_PosX - 2, 0);             char2Arr(WT_arr[MEZ.WT][0], d_PosX - 5, 0);        //dag van de week             char2Arr(WT_arr[MEZ.WT][1], d_PosX - 11, 0);             char2Arr(WT_arr[MEZ.WT][2], d_PosX - 17, 0);             char2Arr(WT_arr[MEZ.WT][3], d_PosX - 23, 0);             char2Arr(48 + MEZ.tag2, d_PosX - 27, 0);           //dag             char2Arr(48 + MEZ.tag1, d_PosX - 33, 0);             char2Arr(M_arr[MEZ.mon12 - 1][0], d_PosX - 39, 0); //maand             char2Arr(M_arr[MEZ.mon12 - 1][1], d_PosX - 43, 0);             char2Arr(M_arr[MEZ.mon12 - 1][2], d_PosX - 49, 0);             char2Arr(M_arr[MEZ.mon12 - 1][3], d_PosX - 55, 0);             char2Arr(M_arr[MEZ.mon12 - 1][4], d_PosX - 61, 0);             char2Arr('2', d_PosX - 68, 0);                     //jaar             char2Arr('0', d_PosX - 74, 0);             char2Arr(48 + MEZ.jahr2, d_PosX - 80, 0);             char2Arr(48 + MEZ.jahr1, d_PosX - 86, 0);             refresh_display(); //alle 50ms             als (f_scrollend_y == ware) {                 f_scrollend_y = false;             }         } //einde 50ms         als (y == 0) {             // doe iets anders         }     }

}

 

Veel Plezier tijdens het bouwproces en tot de volgende post :)

Esp-8266Projekte für anfänger

6 Kommentare

Peter Teubner

Peter Teubner

Nachfrage,
leider bin ich mit der Fehlersuche noch nicht am Ziel.
Die Uhr geht eine Stunde vor.
Hat vielleicht jemand eine Lösung?
mfG
Peter

Peter Teubner

Peter Teubner

Hallo,
habe ein Problem das ich leider noch nicht lösen konnte.
Bis auf die Uhrzeit ist alles korrekt.
Ich habe das Uhrzeitmodul über meinen Arduino( RTC.lib) voreingestellt.
Die Uhr geht eine Stunde vor.
Es wäre schön wenn Sie mir helfen können!!!
mfG

Peter Teubner

udo godeck

udo godeck

mehr als 0:01:0 zeigt diese uhr nichts an

Carsten

Carsten

Servus, ich hab leider ohne Erfolg versucht den Code füt ein D1 mini umzuschreiben.
Worauf muss ich achten oder habt ihr vielleicht einen Code für den D1?
Gruß Carsten

Sven

Sven

Ich habe ebenfalls das Problem mit der Uhr. Sie geht 2 Stunden vor.

Uwe Hendel

Uwe Hendel

Ein sehr nettes kleines Projekt, die Umsetzung hat praktisch sofort geklappt. Einziges Problem, meine Uhr geht 2 Stunden vor, sicher ein Zeitzonen Problem. Nun bin ich mir nicht sicher ob ich schon beim stellen der Uhr mit dem Arduino einen Fehler gemacht habe, oder wo man das in dem Code hier ändern muss. Vielleicht kann mir einer der Profis hier einen Tipp geben.

Einen Kommentar hinterlassen

Alle Kommentare werden vor der Veröffentlichung moderiert

Aanbevolen blog berichten

  1. Installeer ESP32 nu van de raad van bestuur
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP Programmeren via Wi-Fi