- #include <Adafruit_GFX.h>
- #include "Font4x7Fixed.h"
- #include <Adafruit_NeoMatrix.h>
- #include <Adafruit_NeoPixel.h>
- #include <ESP8266WiFi.h>
- #include <time.h>
- #define PIN 4
- #define BRIGHTNESS 5
- const char *ssid = "xxxx";
- const char *password = "xxxx";
- const char* ntpServer = "ro.pool.ntp.org";
- const long gmtOffset_sec = 1 * 60 * 60;
- const int daylightOffset_sec = 3600;
- Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
- NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
- NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
- NEO_GRB + NEO_KHZ800);
- const uint16_t colors[8] = {
- matrix.Color(128, 0, 0), matrix.Color(0, 128, 0), matrix.Color(0, 0, 128),
- matrix.Color(128, 0, 128), matrix.Color(128, 128, 0), matrix.Color(0, 128, 128)
- };
- struct tm timeinfo;
- int pass = 0;
- int x = matrix.width();
- String dash = String(':');
- String minus = String('-');
- String space = String(' ');
- void setup() {
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- }
- configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
- printLocalTime();
- matrix.begin();
- matrix.setFont(&Font4x7Fixed);
- matrix.setTextSize(1);
- matrix.setBrightness(BRIGHTNESS);
- matrix.setTextColor(colors[0]);
- }
- void loop() {
- printLocalTime();
- }
- void printLocalTime() {
- struct tm timeinfo;
- if (!getLocalTime(&timeinfo)) {
- return;
- }
- char timeHour[3];
- strftime(timeHour, 3, "%H", &timeinfo);
- char timeMinute[3];
- strftime(timeMinute, 3, "%M", &timeinfo);
- char timeSeconds[3];
- strftime(timeSeconds, 3, "%S", &timeinfo);
- char timeWeekDay[10];
- strftime(timeWeekDay, 10, "%A", &timeinfo);
- char timeMonth[3];
- strftime(timeMonth, 3, "%B", &timeinfo);
- char timeDay[3];
- strftime(timeDay, 3, "%d", &timeinfo);
- char timeYear[5];
- strftime(timeYear, 5, "%Y", &timeinfo);
- for (uint8_t b = 0; b < 2; b++) {
- matrix.print(b);
- switch (b) {
- case 0:
- String timeShow = String(timeHour) + String(space) + String(dash) + String(space) + String(timeMinute) + String(space) + String(dash) + String(space) + String(timeSoconds);
- matrix.clear();
- matrix.fillScreen(0);
- matrix.setTextWrap(false);
- matrix.setCursor(0, 0);
- matrix.print(timeShow);
- pass++;
- if (pass >= 6) pass = 0;
- matrix.setTextColor(colors[pass]);
- matrix.show();
- delay(1000);
- break;
- case 1:
- String dateShow = String(timeWeekDay) + String(space) + String(timeDay) + String(minus) + String(timeMonth) + String(minus) + String(timeYear);
- static byte scrollCounter[1];
- unsigned long previousMillis = 0;
- const long interval = 300000;
- unsigned long currentMillis = millis();
- if (currentMillis - previousMillis >= interval) {
- previousMillis = currentMillis;
- matrix.clear();
- matrix.fillScreen(0);
- matrix.setTextWrap(false);
- matrix.setCursor(x, 0);
- matrix.print(dateShow);
- if (--x < -36) {
- if (scrollCounter[0] < 1) {
- if (dateShow = true) {
- scrollCounter[0]++;
- }
- return;
- }
- x = matrix.width();
- if (++pass >= 6) pass = 0;
- matrix.setTextColor(colors[pass]);
- }
- matrix.show();
- delay(100);
- break;
- }
- }
- }
- }
Raw Paste