XIAO ESP32S3 Sense dengan LED Ring RGB — Xiao Esp32S3 Sense simulation

XIAO ESP32S3 Sense dengan Seeed Round Display dan LED ring 26 pixel untuk efek running RGB

An interactive Xiao Esp32S3 Sense circuit simulation you can run free in your browser on Velxio, by rsetyo-widayanto.

Components

Sketch code

//= Seeed Round Display + LED Ring Color Controller
// Mode Jam: ketuk di mana saja -> buka menu warna LED
// Mode Menu: pilih warna atau Rainbow, ketuk BACK -> kembali ke jam

#include <M5GFX.h>
#include <lgfx/v1/panel/Panel_GC9A01.hpp>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <SPI.h>


// ==================== PIN DEFINITIONS ====================
// Display (Seeed Round Display shield)
static const int PIN_CS  = 2;   // D1  = GPIO2
static const int PIN_DC  = 4;   // D3  = GPIO4
static const int PIN_BL  = 43;  // D6  = GPIO43
static const int PIN_SCK = 7;   // D8  = GPIO7
static const int PIN_MISO= 8;   // D9  = GPIO8
static const int PIN_MOSI= 9;   // D10 = GPIO9

// LED Ring (WS2812B) -- DIN kabel ke D0 = GPIO1
#define LED_PIN    1
#define LED_COUNT  28
#define LED_BRIGHT 50  // 0-255

Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

// ==================== DISPLAY CLASS ====================
class RoundDisplay : public lgfx::LGFX_Device {
  lgfx::Panel_GC9A01 _gc9a01;
  lgfx::Bus_SPI _spi;
public:
  RoundDisplay() {
    { auto cfg = _spi.config();
      cfg.spi_host = SPI2_HOST; cfg.spi_mode = 0;
      cfg.freq_write = 40000000;
      cfg.pin_sclk = PIN_SCK; cfg.pin_mosi = PIN_MOSI;
      cfg.pin_miso = PIN_MISO; cfg.pin_dc = PIN_DC;
      _spi.config(cfg); _gc9a01.setBus(&_spi); }
    { auto cfg = _gc9a01.config();
      cfg.pin_cs = PIN_CS; cfg.pin_rst = -1;
      cfg.panel_width = 240; cfg.panel_height = 240;
      cfg.invert = true;
      _gc9a01.config(cfg); }
    setPanel(&_gc9a01);
  }
};
static RoundDisplay tft;

// ==================== RTC (PCF8563) ====================
#define RTC_ADDR 0x51
uint8_t bcd2dec(uint8_t v) { return (v >> 4) * 10 + (v & 0x0F); }
uint8_t dec2bcd(uint8_t v) { return ((v / 10) << 4) | (v % 10); }

void rtcSet(uint8_t h, uint8_t m, uint8_t s) {
  Wire.beginTransmission(RTC_ADDR);
  Wire.write(0x02);
  Wire.write(dec2bcd(s)); Wire.write(dec2bcd(m)); Wire.write(dec2bcd(h));
  Wire.endTransmission();
}

bool rtcRead(uint8_t &h, uint8_t &m, uint8_t &s) {
  Wire.beginTransmission(RTC_ADDR);
  Wire.write(0x02);
  if (Wire.endTransmission() != 0) return false;
  if (Wire.requestFrom((int)RTC_ADDR, 3) != 3) return false;
  s = bcd2dec(Wire.read() & 0x7F);
  m = bcd2dec(Wire.read() & 0x7F);
  h = bcd2dec(Wire.read() & 0x3F);
  return true;
}

// ==================== CLOCK DRAWING ====================
static const int CX = 120, CY = 120, R = 110;

void drawHand(float deg, float len, float thick, uint16_t color) {
  float rad = deg * 0.0174533f;
  float x = CX + sin(rad) * len;
  float y = CY - cos(rad) * len;
  for (int o = -thick / 2; o <= thick / 2; o++) {
    tft.drawLine(CX + o, CY, x + o, y, color);
    tft.drawLine(CX, CY + o, x, y + o, color);
  }
}

void drawFace() {
  tft.fillScreen(TFT_BLACK);
  // Jam angka besar
  for (int i = 0; i < 12; i++) {
    float a = i * 30.0f;
    float rad = a * 0.0174533f;
    float x1 = CX + sin(rad) * (R - 5);
    float y1 = CY - cos(rad) * (R -

More projects by rsetyo-widayanto