#define number_of_74hc595s 4
#define numOfRegisterPins number_of_74hc595s * 8
#define dataPin 4
#define latchPin 6
#define clockPin 5
const char* ssid = "SSID";
const char* password = "Wifi Password";
#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET 0
#define UTC_OFFSET_DST 7200
#include <WiFi.h>
#include <time.h>
boolean registers [numOfRegisterPins];
const int afrda = 7024;
bool DirectionState = 0;
uint32_t LEDfull = 0x0;
const int LED00[] = {0x77, 0x11, 0x3E, 0x3B, 0x59, 0x6B, 0x6F, 0x31, 0x7F, 0x7B};
const int LED10[] = {0x7700, 0x1100, 0x3E00, 0x3B00, 0x5900, 0x6B00, 0x6F00, 0x3100, 0x7F00, 0x7B00};
const int LED20[] = {0x770000, 0x110000, 0x3E0000, 0x3B0000, 0x590000, 0x6B0000, 0x6F0000, 0x310000, 0x7F0000, 0x7B0000};
const int LED30[] = {0x00000000, 0x11000000, 0x3E000000, 0x3B000000, 0x59000000, 0x6B000000, 0x6F000000, 0x31000000, 0x7F000000, 0x7B000000, 0x77000000};
const int LEDS0 = 0x80;
uint32_t LEDconn0 = 0x660F0D0D;
const int LEDTESZT00[] = {0x77, 0x11, 0x3E, 0x3B, 0x59, 0x6B, 0x6F, 0x31, 0x7F, 0x7B};
const int LEDTESZT10[] = {0x7700, 0x1100, 0x3E00, 0x3B00, 0x5900, 0x6B00, 0x6F00, 0x3100, 0x7F00, 0x7B00};
const int LEDTESZT20[] = {0x770000, 0x110000, 0x3E0000, 0x3B0000, 0x590000, 0x6B0000, 0x6F0000, 0x310000, 0x7F0000, 0x7B0000};
const int LEDTESZT30[] = {
0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000,
0x00010000, 0x00020000, 0x00040000, 0x00080000, 0x00100000, 0x00200000, 0x00400000, 0x00800000,
0x00000100, 0x00000200, 0x00000400, 0x00000800, 0x00001000, 0x00002000, 0x00004000, 0x00008000,
0x00000001, 0x00000002, 0x00000004, 0x00000008, 0x00000010, 0x00000020, 0x00000040, 0x00000080
};
const int LEDSTESZT0 = 0x80;
uint32_t LEDconnTESZT0 = 0x660F0D0D;
void updateShiftRegister(unsigned long leds, bool isMSBFIRST = true){
unsigned int leds16 = int(leds);
unsigned int leds32 = int(leds>>16);
byte low16LED = lowByte(leds16);
byte high16LED = highByte(leds16);
byte low32LED = lowByte(leds32);
byte high32LED = highByte(leds32);
digitalWrite(latchPin, LOW);
if (isMSBFIRST == false) {
shiftOut(dataPin, clockPin, LSBFIRST, low16LED);
shiftOut(dataPin, clockPin, LSBFIRST, high16LED);
shiftOut(dataPin, clockPin, LSBFIRST, low32LED);
shiftOut(dataPin, clockPin, LSBFIRST, high32LED);
}
else {
shiftOut(dataPin, clockPin, MSBFIRST, high32LED);
shiftOut(dataPin, clockPin, MSBFIRST, low32LED);
shiftOut(dataPin, clockPin, MSBFIRST, high16LED);
shiftOut(dataPin, clockPin, MSBFIRST, low16LED);
}
digitalWrite(latchPin, HIGH);
}
void setup(){
Serial.begin(115200);
Serial.println(F("Initialize System"));
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
delay(500);
//WiFi.begin(ssid, password);
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
Serial.println("Conn");
uint32_t LEDconn = 0xCC1E1A1A;
uint32_t LEDconn0 = 0x660F0D0D;
updateShiftRegister(LEDconn0, DirectionState);
delay(250);
}
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
void loop() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
return;
}
const int a1 = (timeinfo.tm_hour);
const int a2 = (timeinfo.tm_min);
const int a3 = (timeinfo.tm_sec);
int afrda2 = a1 * 100 + a2;
if (a3 % 2 == 0) {
LEDfull = LED30[(afrda2 / 1000) % 10] + LED20[(afrda2 / 100) % 10] + LED10[(afrda2 / 10) % 10] + LED00[afrda2 % 10] + LEDS0;
}
else {
LEDfull = LED30[(afrda2 / 1000) % 10] + LED20[(afrda2 / 100) % 10] + LED10[(afrda2 / 10) % 10] + LED00[afrda2 % 10];
}
Serial.println(LEDfull);
updateShiftRegister(LEDfull, DirectionState);
delay(40);
/*for (int i = 0; i < numOfRegisterPins; i++) {
Serial.println(i);
uint32_t test = (1UL << i);
updateShiftRegister(test, DirectionState);
delay(1000); // 1 másodperc
}*/
/*for (int i = 0; i < 32; i++) {
Serial.println(i);
updateShiftRegister(LEDTESZT30[i], DirectionState);
delay(1000); // 1 másodperc
}*/
}