Search Code

ESP32-S3 RGB LED 매트릭스 인터넷 시계 프로젝트 - 4가지 랜덤 색상

ESP32-S3 RGB LED 매트릭스 인터넷 시계 프로젝트 - 4가지 랜덤 색상

무작위 RGB 색상의 ESP32-S3 인터넷 시계

이 프로젝트는 Wi-Fi에 연결하고 NTP 서버에서 로컬 시간을 동기화하며 내장된 8×8 RGB NeoMatrix에 HH:MM 형식으로 시간을 스크롤하는 ESP32-S3 RGB 매트릭스 인터넷 시계입니다. 이 버전에서는 시간, 콜론, 분이 각각 무작위 색상으로 렌더링되며, 매 전체 스크롤 주기마다 선택되어 끊임없이 변화하는 역동적이고 재미있는 시계 디스플레이를 만듭니다.

ESP32-s3_internet_clock_animation

이 시계의 작동 방식

USB-C로 보드에 전원을 공급하면 ESP32-S3가 Wi-Fi 네트워크에 연결되고 인터넷에서 현재 로컬 시간을 가져옵니다. 시간은 세 부분(시간, 콜론, 분)으로 나뉘며 각 부분은 RGB 매트릭스에 개별적으로 그려집니다. 텍스트가 화면에서 완전히 스크롤되어 사라지면 다음 패스에 대해 새로운 무작위 색상이 선택됩니다.

사용된 라이브러리

이 스케치는 다음 라이브러리를 사용합니다:

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

Arduino 라이브러리 관리자에서 Adafruit NeoMatrix를 설치하세요. Adafruit GFX LibraryAdafruit NeoPixel과 같은 필수 종속성은 자동으로 설치됩니다.

중요한 사용자 설정

매트릭스 데이터 핀(내장 RGB 매트릭스)

RGB 매트릭스가 보드에 통합되어 있지만 데이터 핀은 코드에서 정의해야 합니다:

#define MATRIX_PIN 14

GPIO 14는 ESP32-S3 RGB 매트릭스 보드에서 일반적으로 사용됩니다. 보드 변형이 다른 핀을 사용하는 경우 이 값을 그에 맞게 업데이트하세요.

Wi-Fi SSID 및 비밀번호(대소문자 구분)

Wi-Fi 자격 증명을 자신의 네트워크 정보로 교체하세요:

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

중요: Wi-Fi SSID는 대소문자를 구분합니다. "Book"이라는 SSID는 "book"과 같지 않습니다. 대문자/소문자가 정확히 일치하지 않으면 ESP32-S3가 연결에 실패합니다.

NTP 서버, 시간대 및 일광 절약 시간

시간 동기화는 인터넷 NTP 서버를 사용하여 수행됩니다:

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

로컬 시간은 UTC 및 일광 절약 시간 오프셋을 사용하여 계산됩니다:

// 토론토 근처: UTC-5, DST +1시간
const long  gmtOffset_sec     = -5 * 3600;
const int   daylightOffset_sec = 3600;
  • gmtOffset_sec: UTC 오프셋(초 단위, 위치에 맞게 조정)
  • daylightOffset_sec: DST가 적용 중이면 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 색상 목록이 배열에 저장되며, 각 색상은 0에서 255 사이의 빨강, 초록, 파랑 값으로 정의됩니다:

uint8_t userColors[][3] = {
  {255, 0, 0},    // 빨강
  {0, 255, 0},    // 초록
  {0, 0, 255},    // 파랑
  {255, 165, 0},  // 주황
  {255, 0, 255},  // 자홍
  {0, 255, 255},  // 청록
  {255, 255, 0}   // 노랑
};

매 전체 스크롤 주기마다:

  • 시간 숫자에 무작위 색상이 할당됩니다
  • 콜론은 다른 무작위 색상을 받습니다
  • 분 숫자는 또 다른 무작위 색상을 받습니다

이로 인해 시계가 시각적으로 흥미롭게 유지되는 끊임없이 변화하는 색상 조합이 생성됩니다. 사용자 정의 색상을 만들려면 RGB 색상 선택 도구를 사용할 수 있습니다: RGB 색상 선택기.

시간 렌더링 로직

시간은 세 가지 구성 요소로 나뉩니다:

  • 시간: HH
  • 콜론: :
  • 분: MM

각 부분은 고유한 색상을 가질 수 있도록 개별적으로 그려지며, 모든 부분이 함께 이동하여 8×8 디스플레이에서 부드러운 스크롤 애니메이션을 형성합니다.

무작위 색상 생성

색상의 무작위성을 보장하기 위해 스케치는 시작 시 연결되지 않은 아날로그 핀을 사용하여 난수 생성기를 시드합니다:

randomSeed(analogRead(0));

이렇게 하면 전원을 켤 때마다 그리고 매 스크롤 주기마다 색상 조합이 다르게 됩니다.

시연

스케치를 업로드하고 USB-C로 보드에 전원을 공급한 후:

  • ESP32-S3가 Wi-Fi 네트워크에 연결됩니다
  • 시간이 인터넷에서 동기화됩니다
  • 시간이 HH:MM 형식으로 스크롤됩니다
  • 시간, 콜론, 분이 각 주기마다 무작위 색상으로 변경됩니다
  • 디스플레이가 밤에 자동으로 어두워집니다

다운로드 및 링크

전체 소스 코드는 이 문서 아래에 제공됩니다. 유용한 도구와 참고 자료는 이 문서 아래에 링크되어 있습니다.

이미지

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
873-ESP32-S3 RGB LED Matrix Internte Clock Project 4 - Random Color
언어: C++
/*
 * =====================================================================================
 * ESP32-S3 INTERNET RGB CLOCK (8x8 Matrix) - Project 4- Random Color
 * =====================================================================================
 watch video https://youtube.com/shorts/4iWjLiD7fS8
 📚⬇️ Download and resource page https://robojax.com/RJT843
 * 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).
 * =====================================================================================
 */
/*
 * =====================================================================================
 * ESP32-S3 INTERNET CLOCK - MULTI-COLOR ELEMENTS
 * =====================================================================================
 * Each part of the time (HH : MM) gets a different random color from your list.
 * Colors only change once the full scroll cycle is finished.
 * =====================================================================================
 */

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

#define MATRIX_PIN 14

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

uint8_t userColors[][3] = {
  {255, 0, 0},    // Red
  {0, 255, 0},    // Green
  {0, 0, 255},    // Blue
  {255, 165, 0},  // Orange
  {255, 0, 255},  // Magenta
  {0, 255, 255},  // Cyan
  {255, 255, 0}   // Yellow
};
int totalColors = sizeof(userColors) / sizeof(userColors[0]);

// Variables to store the current random color indices
int hourColorIdx = 0;
int colonColorIdx = 1;
int minColorIdx = 2;

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

char hourText[3], minText[3];
int16_t scrollX = 8;
unsigned long lastScrollMs = 0;
const uint16_t scrollIntervalMs = 100;

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


// NTP (time) server
const char* ntpServer = "pool.ntp.org";

// Toronto-ish: UTC-5, plus 1 hour DST
const long  gmtOffset_sec     = -5 * 3600;  // -5 hours
const int   daylightOffset_sec = 3600;      // +1 hour for DST


void updateTimeParts() {
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) return;
  
  snprintf(hourText, sizeof(hourText), "%02d", timeinfo.tm_hour);
  snprintf(minText, sizeof(minText), "%02d", timeinfo.tm_min);

  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);
  
  int x = scrollX;

  // 1. Draw Hours
  matrix.setTextColor(matrix.Color(userColors[hourColorIdx][0], userColors[hourColorIdx][1], userColors[hourColorIdx][2]));
  matrix.setCursor(x, 0);
  matrix.print(hourText);
  x += 12; // Move 12 pixels (2 digits * 6px)

  // 2. Draw Colon
  matrix.setTextColor(matrix.Color(userColors[colonColorIdx][0], userColors[colonColorIdx][1], userColors[colonColorIdx][2]));
  matrix.setCursor(x, 0);
  matrix.print(":");
  x += 6; // Move 6 pixels

  // 3. Draw Minutes
  matrix.setTextColor(matrix.Color(userColors[minColorIdx][0], userColors[minColorIdx][1], userColors[minColorIdx][2]));
  matrix.setCursor(x, 0);
  matrix.print(minText);

  matrix.show();
  scrollX--;

  // Total width is roughly 30 pixels (HH=12, :=6, MM=12)
  if (scrollX < -30) {
    scrollX = matrix.width(); 
    
    // Pick NEW random colors for the next cycle
    hourColorIdx = random(0, totalColors);
    colonColorIdx = random(0, totalColors);
    minColorIdx = random(0, totalColors);
  }
}

void setup() {
  Serial.begin(115200);
  
  // Seed the random generator using an unconnected analog pin
  randomSeed(analogRead(0));

  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  
  // Configure time via NTP
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  Serial.println("Waiting for time...");
  delay(2000); // small wait for initial sync
  
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(DAY_BRIGHTNESS);
}

void loop() {
  if (millis() % 1000 == 0) updateTimeParts();

  if (millis() - lastScrollMs >= scrollIntervalMs) {
    lastScrollMs = millis();
    scrollTime();
  }
}

자원 및 참고자료

파일📁

프리징 파일