Muhammad Fauzan UR
Published © CERN-OHL2

Running Text and Clock with XIAO ESP32S3 and

Scrolling text display and digital clock using the XIAO ESP32S3 from Seeed Studio and a MAX7219-based 8x8 LED Matrix

BeginnerFull instructions provided1 hour75
Running Text and Clock with XIAO ESP32S3 and

Things used in this project

Hardware components

Seeed Studio XIAO ESP32S3 Sense
Seeed Studio XIAO ESP32S3 Sense
×1
LED Dot Matrix Display, Red
LED Dot Matrix Display, Red
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Running Text and Clock with XIAO ESP32S3 and LED MAX7219

Arduino
#include <MD_Parola.h>
#include <MD_MAX72XX.h>
#include <WiFi.h>
#include <time.h>
#include <SPI.h>

// WiFi credentials
const char* ssid = "YOUR_SSID";
const char* password = "YOUR_PASSWORD";

// MAX7219 config
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define DATA_PIN  6
#define CLK_PIN   7
#define CS_PIN    5

MD_Parola display = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// Text to be displayed (can be changed according to needs)
const char* runningText = "SELAMAT DATANG DI UNIVERSITAS RAHARJA";

unsigned long lastSwitch = 0;
int mode = 0; // 0: jam, 1: running text
const int switchInterval = 12000; // change the display every 12 seconds

void setup() {
  Serial.begin(115200);
  display.begin();
  display.setIntensity(8);
  display.displayClear();

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nWiFi Connected");

  // Synchronizing NTP time to GMT+7
  configTime(7 * 3600, 0, "pool.ntp.org", "time.nist.gov");

  // Show the scroll while waiting for available time
  display.displayScroll("Connecting time...", PA_LEFT, PA_SCROLL_LEFT, 50);
  while (!time(nullptr)) {
    delay(1000);
  }
  display.displayClear();
}

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

  // Change the mode every few seconds
  if (nowMillis - lastSwitch > switchInterval) {
    mode = 1 - mode; // toggle between 0 and 1
    lastSwitch = nowMillis;
    display.displayClear();
  }

  if (mode == 0) {
    // Digital clock mode
    static char timeStr[9]; // "HH:MM:SS"
    time_t now = time(nullptr);
    struct tm* tm_info = localtime(&now);
    snprintf(timeStr, sizeof(timeStr), "%02d:%02d:%02d", tm_info->tm_hour, tm_info->tm_min, tm_info->tm_sec);

    display.setTextAlignment(PA_CENTER);
    display.print(timeStr);

    delay(1000); // update time every second
  } else {
    // Scrolling text mode
    if (display.displayAnimate()) {
      display.displayScroll(runningText, PA_LEFT, PA_SCROLL_LEFT, 50);
    }
  }
}

Credits

Muhammad Fauzan UR
2 projects • 3 followers

Comments