本教程是的一部分: ESP32-S3 RGB LED 点阵
这是一个很棒的项目,可以使用 ESP32-S3 RGB 矩阵模块进行创作,兼具趣味性和实用性。本文下方有其他相关视频的链接。
ESP32-S3 RGB LED矩阵互联网时钟项目 - 带日期的3种夜间颜色
ESP32-S3 RGB NeoMatrix 智能时钟,具备自动昼夜亮度调节功能
这个项目是一个ESP32-S3 RGB矩阵互联网时钟,可以在白天和夜晚自动调节亮度。ESP32-S3连接到Wi-Fi,从NTP服务器同步当前时间,并滚动显示时间。HH:MM在8×8 RGB NeoMatrix上格式化。时钟还支持固定或循环的RGB颜色用于显示文本。

这个钟表的功能是什么
在启动后,ESP32-S3连接到您的Wi-Fi网络并从互联网获取当前本地时间。时间在LED矩阵上流畅地滚动。在夜间,显示屏会自动调暗至较低亮度,而在白天则会切换回较亮的级别。
使用的库
此草图使用以下库:

#include <WiFi.h>
#include "time.h"
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>安装Adafruit NeoMatrix通过Arduino库管理器。所有所需的依赖项,例如Adafruit GFX Library和Adafruit NeoPixel将自动安装。

重要用户配置
Wi-Fi SSID 和密码(区分大小写)
用自己的 Wi-Fi 凭据替换以下值:

const char* WIFI_SSID = "WiFi";
const char* WIFI_PASSWORD = "passW0rd";重要:Wi-Fi SSID是区分大小写一个名为SSID的网络"Book"是不与...相同"book"如果大小写不完全匹配,ESP32 将无法连接。
NTP服务器、时区和夏令时
时钟使用以下 NTP 服务器同步时间:
const char* ntpServer = "pool.ntp.org";本地时间是通过以下时差计算得出的:
const long gmtOffset_sec = -5 * 3600;
const int daylightOffset_sec = 3600;gmtOffset_sec定义您的UTC偏移量(以秒为单位)daylightOffset_sec当夏令时生效时增加一小时(使用0如果不需要的话
这些值适用于:
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);自动日夜亮度调整
显示亮度会根据当前时间自动调整:
const int DAY_BRIGHTNESS = 40;
const int NIGHT_BRIGHTNESS = 5;
const int NIGHT_START_HOUR = 22; // 10 PM
const int NIGHT_END_HOUR = 6; // 6 AM在晚上10点到早上6点之间,矩阵亮度会降低,以便在黑暗环境中保持舒适。超出这些时间段,日间亮度将恢复到正常水平。您可以调整这些数值以适应您的房间照明。
RGB颜色配置
时钟文本颜色使用RGB(红,绿,蓝)值定义,每个通道的范围是0到255。可以在数组中存储多种颜色并自动循环:
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
};如果useFixedColor被设置为true,时钟总是使用一种颜色。如果设置为false颜色会在每次完整滚动时间后自动变化。
要快速找到任何颜色的确切 RGB 值,请使用 RGB 颜色选择器工具:RGB颜色选择器.
时间显示和滚动
当前时间格式为HH:MM并存储在一个小字符缓冲区中。由于显示器只有8个像素宽,文本从右向左平滑滚动。一旦时间完全离开了显示屏,下一种颜色(如果启用)将在下一次循环中被选中。
演示
上传草图后:
- ESP32-S3 连接到 Wi-Fi
- 时间从互联网同步。
- 当前时间在RGB矩阵上滚动。
- 亮度在白天和夜晚之间自动变化
- 文本颜色保持固定或根据您的设置循环变化
下载和链接
本文下方提供了完整的源代码。本文下方有各部分、工具和数据表的链接。
本教程是……的一部分: ESP32-S3 RGB LED 点阵
- ESP32-S3 RGB LED矩阵项目 1- 基本点阵
- ESP32-S3 RGB LED矩阵项目2 - 滚动文字
- ESP32-S3 RGB LED矩阵项目3 - 手机文本
- ESP32-S3 RGB LED矩阵项目4 - 倾斜点
- ESP32-S3 RGB LED矩阵项目5 - 箭头始终向上
- ESP32-S3 RGB LED矩阵项目6 - Cible游戏
- ESP32-S3 RGB LED 矩阵 Wi-Fi + NTP 时钟项目 - 1 基本时钟
- ESP32-S3 RGB LED矩阵网络时钟项目 - 2个时钟多彩时间和日期显示
- ESP32-S3 RGB LED 矩阵网络时钟项目 - 5 种彩虹色
- ESP32-S3 RGB LED矩阵互联网时钟项目 - 4种随机颜色
- ESP32-S3 RGB LED矩阵测试,RGB,GRB设置
/*
* =====================================================================================
* ESP32-S3 INTERNET RGB CLOCK (8x8 Matrix) - Project 3- Night color with Date
* =====================================================================================
watch video https://youtube.com/shorts/4iWjLiD7fS8
📚⬇️ Download and resource page https://robojax.com/RJT840
* Author: Gemini (AI Thought Partner) & 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 after the time finishes a full scroll.
* 3. Auto-Brightness: Dims the LEDs during night hours (User-configurable).
* =====================================================================================
*/
#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; // 10 PM
const int NIGHT_END_HOUR = 6; // 6 AM
// --- 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]);
// --- INTERVALS ---
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";
int16_t scrollX = 8;
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = -5 * 3600;
const int daylightOffset_sec = 3600;
void updateTimeText() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) return;
// Format HH:MM
snprintf(timeText, sizeof(timeText), "%02d:%02d", timeinfo.tm_hour, timeinfo.tm_min);
// Apply Auto-Brightness
if (timeinfo.tm_hour >= NIGHT_START_HOUR || timeinfo.tm_hour < NIGHT_END_HOUR) {
matrix.setBrightness(NIGHT_BRIGHTNESS);
} else {
matrix.setBrightness(DAY_BRIGHTNESS);
}
}
void scrollTime() {
matrix.fillScreen(0);
// Pick the color (Fixed or Cycle)
int idx = useFixedColor ? fixedColorIndex : currentColorIndex;
matrix.setTextColor(matrix.Color(userColors[idx][0], userColors[idx][1], userColors[idx][2]));
matrix.setCursor(scrollX, 0);
matrix.print(timeText);
matrix.show();
scrollX--;
// Width for "HH:MM" is roughly 30 pixels
int16_t textWidth = 30;
// TRIGGER: When time is fully off-screen
if (scrollX < -textWidth) {
scrollX = matrix.width(); // Reset position to right side
// Cycle to the next color in the array for the next pass
if (!useFixedColor) {
currentColorIndex = (currentColorIndex + 1) % totalColors;
Serial.print("Next cycle color index: ");
Serial.println(currentColorIndex);
}
}
}
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);
updateTimeText();
}
void loop() {
unsigned long now = millis();
// Update time digits and brightness once per second
if (now - lastTimeUpdateMs >= timeUpdateIntervalMs) {
lastTimeUpdateMs = now;
updateTimeText();
}
// Handle the scrolling animation
if (now - lastScrollMs >= scrollIntervalMs) {
lastScrollMs = now;
scrollTime();
}
}
|||您可能需要的东西
-
亚马逊从亚马逊购买ESP32-S3 RGB矩阵amzn.to
-
易趣从eBay购买ESP32-S3 RGB矩阵ebay.us
-
全球速卖通从AliExpress购买ESP32-S3 RGB矩阵 (2)s.click.aliexpress.com
-
全球速卖通在AliExpress上购买ESP32-S3 RGB矩阵s.click.aliexpress.com
资源与参考
-
视频ESP32-S3 RGB LED矩阵互联网时钟项目短视频youtube.com
-
内部颜色选择器工具robojax.com
文件📁
Fritzing 文件
-
esp32-S3-supermini-tht Fritzing 部件
esp32-S3-supermini-tht.fzpz0.02 MB