aaaaaaaaaaaa — ESP32 simulation

Reloj de escritorio con animacion de lluvia digital estilo Matrix en TFT ILI9341, controlado por botones (color, hora y menu de ajuste) sobre ESP32.

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by dave.

Components

Sketch code

// Digital Rain Clock
// Adapted from https://github.com/rhammell/digital-rain-clock
// The FT6206 capacitive touchscreen is replaced by 7 physical pushbuttons
// (the simulator has no touch model). Everything else keeps the original
// behavior: digital rain animation, time overlay, color schemes, settings menu.

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <ESP32Time.h>

// ---- TFT (hardware SPI, VSPI: SCK=18, MOSI=23, MISO=19) ----
#define TFT_DC   2
#define TFT_CS   5
#define TFT_RST  4

SPIClass tftSPI(VSPI);
Adafruit_ILI9341 tft(&tftSPI, TFT_DC, TFT_CS, TFT_RST);

// ---- Buttons (INPUT_PULLUP, pressed = LOW) ----
#define BTN_COLOR     13   // cycle color scheme (was: bottom-left touch)
#define BTN_SHOW      14   // show time overlay        (was: center touch)
#define BTN_SETTINGS  26   // toggle settings menu     (was: top-left touch)
#define BTN_HOUR_UP   27
#define BTN_HOUR_DOWN 32
#define BTN_MIN_UP    33
#define BTN_MIN_DOWN  25

// Screen dimensions - portrait
const int SCREEN_W = 240;
const int SCREEN_H = 320;

// Text scale
const int TEXT_SCALE = 1;

// Font pixel width and height
const int FONT_PIXEL_W = 6;
const int FONT_PIXEL_H = 8;
const int CHAR_W = FONT_PIXEL_W * TEXT_SCALE;
const int CHAR_H = FONT_PIXEL_H * TEXT_SCALE;

// Number of columns and rows
const int NUM_COLS = SCREEN_W / CHAR_W;
const int NUM_ROWS = SCREEN_H / CHAR_H;

// Column-specific tail length range (in rows)
const int MIN_TAIL_LEN = 14;
const int MAX_TAIL_LEN = 20;

// Global speed range (ms per row step)
const uint16_t MIN_INTERVAL = 60;
const uint16_t MAX_INTERVAL = 160;

// Clock overlay parameters
const int  TIME_TEXT_LENGTH          = 5;
const uint16_t TIME_OVERLAY_DURATION_MS = 3600;
const int TIME_TEXT_SIZE        = 6;
char timeText[TIME_TEXT_LENGTH + 1] = "12:00";

// Column state
struct ColumnState {
  int headRow;
  uint16_t intervalMs;
  uint32_t lastUpdateMs;
  uint8_t tailLength;
};

// Array of column states
ColumnState columns[NUM_COLS];

// Character buffer for trail characters
char glyphs[NUM_COLS][NUM_ROWS];

// Colors for rain (head + trail levels) and background
uint16_t matrixHeadColor;
uint16_t matrixTrailBright;
uint16_t matrixTrailDim;
uint16_t matrixTrailDark;
uint16_t matrixBgColor;

// Real-time clock
ESP32Time rtc;

// Last displayed minute
int lastDisplayedMinute = -1;

// Color scheme struct
struct ColorScheme {
  uint16_t head;
  uint16_t bright;
  uint16_t dim;
  uint16_t dark;
};

// Number of color schemes
const uint8_t NUM_COLOR_SCHEMES = 5;

// Array of color schemes
ColorScheme colorSchemes[NUM_COLOR_SCHEMES];

// Current color scheme
uint8_t currentColorScheme = 0;

// Debounce timers for the buttons
const uint16_t COLOR_TOGGLE_DEBOUNCE_MS = 250;
uint32_t lastColorToggleMs = 0;
const uint16_t SHOW_DEBOUNCE_MS = 250;
uint32_t lastShowMs = 0;
const uint16_t SETTINGS_TOGGLE_DEBOUNCE_MS = 250;
uint32_t lastSettingsToggleMs = 0;
const uint16_t SETTINGS_BUTTON_DEBOUNCE_MS = 200;
uint32_t la

More projects by dave