搜索代码

ESP32-S3 RGB LED矩阵网络时钟项目 - 2个时钟多彩时间和日期显示

ESP32-S3 RGB LED矩阵网络时钟项目 - 2个时钟多彩时间和日期显示

ESP32-S3 RGB NeoMatrix互联网时钟,带时间和日期显示

这个项目是一个增强版的ESP32-S3 RGB矩阵互联网时钟,不仅显示当前时间,还定期显示日期。ESP32-S3连接到Wi-Fi,从NTP服务器同步时间,并滚动显示。HH:MM或日期(例如SEP 21) 在一个8×8 RGB NeoMatrix上。该显示器支持自动日夜亮度控制和可定制的RGB颜色。

ESP32-s3互联网时钟动画

这个钟表的功能

连接到您的 Wi-Fi 网络后,ESP32-S3 从互联网获取当前本地时间。时钟通常滚动显示时间,但在固定的时间间隔内切换为显示日期。文本颜色可以固定为一种颜色或自动循环显示多个用户定义的颜色。夜间亮度会自动降低,以使屏幕更容易看。

使用的库

该草图依赖于以下库:

#include <WiFi.h>
#include "time.h"
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

安装Adafruit NeoMatrix来自Arduino库管理器。所有所需的依赖项,例如Adafruit GFX LibraryAdafruit NeoPixel将自动安装。

重要用户配置

Wi-Fi SSID 和密码(区分大小写)

您必须用您自己的网络信息替换Wi-Fi凭据:

const char* WIFI_SSID     = "WiFi";
const char* WIFI_PASSWORD = "passW0rd";

重要:Wi-Fi SSID是区分大小写例如,一个名为"Book"相同于"book"如果大小写不完全匹配,ESP32将无法连接。

NTP服务器、时区和夏令时

时钟使用互联网时间服务器:

const char* ntpServer = "pool.ntp.org";

当地时间是根据以下时区差计算的:

const long  gmtOffset_sec     = -5 * 3600; 
const int   daylightOffset_sec = 3600;
  • gmtOffset_sec您与协调世界时的时差(秒)(例如:UTC-5 =-5 * 3600)
  • daylightOffset_sec使用3600为了夏令时或0如果不使用夏令时

这些设置是通过以下方式应用的:

configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);

亮度控制(白天/夜晚)

该项目会根据一天中的时刻自动调整亮度:

const int DAY_BRIGHTNESS = 40;
const int NIGHT_BRIGHTNESS = 5;
const int NIGHT_START_HOUR = 22;
const int NIGHT_END_HOUR = 6;

在晚上10点到早上6点之间,亮度会降低,以使显示在黑暗环境中 менее 分散注意力。您可以调整这些数值以满足您的偏好。

RGB颜色配置

时钟支持固定色彩模式和自动颜色循环。用户定义的RGB颜色存储在一个数组中:

uint8_t userColors[][3] = {
  {17, 43, 171},  // Light Blue
  {255, 0, 0},    // Red
  {0, 255, 0},    // Green
  {255, 165, 0},  // Orange
  {255, 0, 255}   // Magenta
};

每种颜色使用范围从 0 到 255 的 RGB(红、绿、蓝)值。通过改变这些数字,您可以为显示器创建几乎任何颜色。如果useFixedColor设置为true,时钟总是使用一种颜色。如果设置为false颜色在每次完全滚动后会自动改变。

要快速找到您想要的任何颜色的准确 RGB 值,请使用 RGB 颜色选择器工具:RGB颜色选择器.

时间和日期格式化

时间格式为HH:MM并存储在一个小字符缓冲区中。日期格式化为大写字符串,例如SEP 21显示屏会在固定的间隔内自动切换时间和日期。

在8×8显示器上的滚动逻辑

由于8×8矩阵太小,无法一次性显示完整文本,因此草图会横向滚动文本。一旦文本完全离开显示屏,颜色会更新,并在需要时内容会在时间和日期之间切换。

演示

上传草图后:

  • ESP32连接到Wi-Fi
  • 时间从互联网同步。
  • 当前时间在矩阵中滚动。
  • 日期定期出现
  • 亮度会根据白天和夜晚自动调整。

下载和链接

完整的源代码在本文下面提供。与各个部分、工具和数据表的链接也在本文下面提供。

图像

ESP32 S3 Matrix
ESP32 S3 Matrix
ESP32 S3 Matrix  pin out
ESP32 S3 Matrix pin out
ESP32-S3_RGB_8x8_matrix-3
ESP32-S3_RGB_8x8_matrix-3
ESP32-S3_RGB_8x8_matrix1
ESP32-S3_RGB_8x8_matrix1
ESP32-S3_RGB_8x8_matrix-2
ESP32-S3_RGB_8x8_matrix-2
ESP32-s3_internet_clock_animation
ESP32-s3_internet_clock_animation
869-ESP32-S3 RGB LED Matrix Internte Clock Project 2 - Multi Color with Date
语言: C++
/*
 * =====================================================================================
 * ESP32-S3 INTERNET RGB CLOCK (8x8 Matrix) - Project 2
 Multi color
 * =====================================================================================
 watch video https://youtube.com/shorts/4iWjLiD7fS8
 📚⬇️ Download and resource page https://robojax.com/RJT839
 * Author:  Ahmad Shamshiri (Robojax.com)
 * Date: 07 Jan 2026
 * * FEATURES:
 * 1. WiFi/NTP Time: Syncs automatically with internet time servers.
 * 2. Cycle-Based Color: Color changes ONLY when text finishes a full scroll.
 * 3. Auto-Brightness: Dims the LEDs during night hours (User-configurable).
 * 4. Periodic Date: Scrolls the date (e.g., "JAN 07") every 2 minutes.
 * * USER CONFIGURATION GUIDE:
 * -------------------------
 * - WiFi: Change 'WIFI_SSID' and 'WIFI_PASSWORD' to your local network.
 * - Colors: Add or remove {R, G, B} sets in the 'userColors' array.
 * - Night Mode: Adjust 'NIGHT_START_HOUR' and 'NIGHT_BRIGHTNESS'.
 * =====================================================================================
 */

#include <WiFi.h>
#include "time.h"
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

#define MATRIX_PIN 14

// --- BRIGHTNESS CONFIGURATION ---
const int DAY_BRIGHTNESS = 40;
const int NIGHT_BRIGHTNESS = 5;
const int NIGHT_START_HOUR = 22; 
const int NIGHT_END_HOUR = 6;

// --- COLOR CONFIGURATION ---
bool useFixedColor = false; 
int fixedColorIndex = 0;    
uint8_t userColors[][3] = {
  {17, 43, 171},  // Light Blue
  {255, 0, 0},    // Red
  {0, 255, 0},    // Green
  {255, 165, 0},  // Orange
  {255, 0, 255}   // Magenta
};

// 👇 REPLACE these with your real home WiFi name & password
const char* WIFI_SSID     = "WiFi";
const char* WIFI_PASSWORD = "passW0rd";


int currentColorIndex = 0;
int totalColors = sizeof(userColors) / sizeof(userColors[0]);

// --- DATE/TIME INTERVALS ---
unsigned long lastDateShowMs = 0;
const uint32_t dateIntervalMs = 30000; // 2 minutes
unsigned long lastTimeUpdateMs = 0;
const uint16_t timeUpdateIntervalMs = 1000;
unsigned long lastScrollMs = 0;
const uint16_t scrollIntervalMs = 100;

// --- GLOBAL VARIABLES ---
Adafruit_NeoMatrix matrix(8, 8, MATRIX_PIN,
  NEO_MATRIX_TOP    + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS   + NEO_MATRIX_PROGRESSIVE,
  NEO_RGB           + NEO_KHZ800);

char timeText[6] = "00:00";
char dateText[10] = "";
char currentDisplayText[12] = ""; 
int16_t scrollX = 8;


const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec     = -5 * 3600; 
const int   daylightOffset_sec = 3600;

void updateTimeAndDate() {
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) return;
  
  snprintf(timeText, sizeof(timeText), "%02d:%02d", timeinfo.tm_hour, timeinfo.tm_min);
  strftime(dateText, sizeof(dateText), "%b %d", &timeinfo);
  for (int i = 0; dateText[i]; i++) dateText[i] = toupper(dateText[i]);

  if (timeinfo.tm_hour >= NIGHT_START_HOUR || timeinfo.tm_hour < NIGHT_END_HOUR) {
    matrix.setBrightness(NIGHT_BRIGHTNESS);
  } else {
    matrix.setBrightness(DAY_BRIGHTNESS);
  }
}

void scrollDisplay() {
  matrix.fillScreen(0);
  
  // FIXED LOGIC: Uses currentColorIndex which only changes at the end of a scroll
  int idx = useFixedColor ? fixedColorIndex : currentColorIndex;
  matrix.setTextColor(matrix.Color(userColors[idx][0], userColors[idx][1], userColors[idx][2]));

  matrix.setCursor(scrollX, 0);
  matrix.print(currentDisplayText);
  matrix.show();

  scrollX--;

  int16_t textWidth = strlen(currentDisplayText) * 6;
  
  // THE TRIGGER POINT: This happens only when text is fully off-screen
  if (scrollX < -textWidth) {
    scrollX = matrix.width(); 
    
    // 1. Cycle the color now and only now
    if (!useFixedColor) {
      currentColorIndex = (currentColorIndex + 1) % totalColors;
    }

    // 2. Decide whether to switch between Time and Date
    if (millis() - lastDateShowMs > dateIntervalMs) {
      strcpy(currentDisplayText, dateText);
      lastDateShowMs = millis();
    } else {
      strcpy(currentDisplayText, timeText);
    }
  }
}

void setup() {
  Serial.begin(115200);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(DAY_BRIGHTNESS);
  
  updateTimeAndDate();
  strcpy(currentDisplayText, timeText); 
}

void loop() {
  unsigned long now = millis();

  if (now - lastTimeUpdateMs >= timeUpdateIntervalMs) {
    lastTimeUpdateMs = now;
    updateTimeAndDate(); 
  }

  if (now - lastScrollMs >= scrollIntervalMs) {
    lastScrollMs = now;
    scrollDisplay();
  }
}

|||您可能需要的东西

资源与参考

文件📁

Fritzing 文件