ESP32 7x72 NeoPixel Matrix Display — ESP32 simulation

A large 7x72 NeoPixel matrix display controlled by an ESP32.

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

Components

Sketch code

#include <FastLED.h>

#define DATA_PIN 21
#define WIDTH 72
#define HEIGHT 7
#define NUM_LEDS (WIDTH * HEIGHT)
#define BRIGHTNESS 80
#define SERPENTINE false  // false=Velxio, true=panel fisik zig-zag

CRGB leds[NUM_LEDS];

uint16_t XY(uint8_t x, uint8_t y) {
  if (SERPENTINE && (y & 1)) {
    return y * WIDTH + (WIDTH - 1 - x);
  }
  return y * WIDTH + x;
}

void pixel(int x, int y, CRGB warna) {
  if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT) {
    leds[XY(x, y)] = warna;
  }
}

const char polaMata[7][31] = {
  "RRRRR.........................",
  ".RRRRRRRRRR...................",
  "..RWWWWWWWRRRRRR..............",
  "...RWWWWWWWWWWWWRRRRR.........",
  "....RWWWWWWWWWWWWWWWRRR.......",
  ".....RRWWWWWWWWWWWWWWWRR......",
  "........RRRRRRRRRRRRRRRRRR...."
};

void satuMata(bool kanan, int geserPupil, int bukaan, bool aktif) {
  int offsetX = kanan ? 40 : 2;
  int pusatPupil = 14 + geserPupil;

  for (int y = 0; y < HEIGHT; y++) {
    for (int x = 0; x < 30; x++) {
      int sx = kanan ? 29 - x : x;
      char bentuk = polaMata[y][sx];
      CRGB warna = CRGB::Black;

      if (aktif && abs(y - 3) * 25 <= bukaan) {
        if (bentuk == 'R') warna = CRGB(255, 0, 0);
        if (bentuk == 'W') warna = CRGB(180, 180, 180);

        int posisiPupil = kanan ? 29 - pusatPupil : pusatPupil;
        int dx = x - posisiPupil;
        int dy = y - 4;

        if (bentuk == 'W' && dx * dx + dy * dy <= 6)
          warna = CRGB(255, 0, 0);
        if (bentuk == 'W' && abs(dx) <= 1 && abs(dy) <= 1)
          warna = CRGB::Black;
      }
      pixel(offsetX + x, y, warna);
    }
  }
}

void gambarMata(int pupil, int bukaan, bool kiri, bool kanan) {
  fill_solid(leds, NUM_LEDS, CRGB::Black);
  satuMata(false, pupil, bukaan, kiri);
  satuMata(true, pupil, bukaan, kanan);
  FastLED.show();
}

void tesWarna() {
  fill_solid(leds, NUM_LEDS, CRGB::Red);
  FastLED.show();
  delay(600);
  fill_solid(leds, NUM_LEDS, CRGB::Green);
  FastLED.show();
  delay(600);
  fill_solid(leds, NUM_LEDS, CRGB::Blue);
  FastLED.show();
  delay(600);
  FastLED.clear(true);
}

void setup() {
  Serial.begin(115200);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.clear(true);
  Serial.println("Tes RGB lalu animasi mata 72x7");
  tesWarna();
}

void loop() {
  // Mata membuka
  for (int buka = 0; buka <= 100; buka += 10) {
    gambarMata(0, buka, true, true);
    delay(70);
  }
  delay(500);

  // Melirik kiri dan kanan
  for (int p = 0; p >= -5; p--) {
    gambarMata(p, 100, true, true);
    delay(120);
  }
  delay(300);
  for (int p = -5; p <= 5; p++) {
    gambarMata(p, 100, true, true);
    delay(100);
  }
  delay(300);
  for (int p = 5; p >= 0; p--) {
    gambarMata(p, 100, true, true);
    delay(120);
  }

  // Berkedip
  gambarMata(0, 50, true, true);
  delay(80);
  gambarMata(0, 0, true, true);
  delay(150);
  gambarMata(0, 50, true, true);
  delay(80);
  gambarMata(0, 100, true, true);
  delay(500);

  // Strobo kiri d

More projects by rsetyo-widayanto