LucesLed — ESP32 simulation

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

Components

Sketch code

#include <Adafruit_NeoPixel.h>

#define LEDS_POR_MATRIZ 64
#define BRILLO 55
#define PIN_SUP_IZQ 21
#define PIN_SUP_CEN 4
#define PIN_SUP_DER 5
#define PIN_MED_IZQ 18
#define PIN_MED_CEN 19
#define PIN_MED_DER 22
#define PIN_INF_CEN 23

Adafruit_NeoPixel supIzq(LEDS_POR_MATRIZ, PIN_SUP_IZQ, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel supCen(LEDS_POR_MATRIZ, PIN_SUP_CEN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel supDer(LEDS_POR_MATRIZ, PIN_SUP_DER, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel medIzq(LEDS_POR_MATRIZ, PIN_MED_IZQ, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel medCen(LEDS_POR_MATRIZ, PIN_MED_CEN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel medDer(LEDS_POR_MATRIZ, PIN_MED_DER, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel infCen(LEDS_POR_MATRIZ, PIN_INF_CEN, NEO_GRB + NEO_KHZ800);

uint32_t verdeOscuro;
uint32_t verde;
uint32_t verdeClaro;
uint32_t rojo;
uint32_t amarillo;
uint32_t azul;
uint32_t magenta;
uint32_t blanco;
uint32_t marron;

Adafruit_NeoPixel* obtenerMatriz(int x, int y)
{
  if (x < 0 || x > 23 || y < 0 || y > 23)
    return nullptr;

  if (y < 8)
  {
    if (x < 8)
      return &supIzq;

    if (x < 16)
      return &supCen;

    return &supDer;
  }

  if (y < 16)
  {
    if (x < 8)
      return &medIzq;

    if (x < 16)
      return &medCen;

    return &medDer;
  }

  if (x >= 8 && x < 16)
    return &infCen;

  return nullptr;
}

void pixel(int x, int y, uint32_t color)
{
  Adafruit_NeoPixel* matriz = obtenerMatriz(x, y);

  if (matriz == nullptr)
    return;

  int localX = x % 8;
  int localY = y % 8;

  int indice = localY * 8 + localX;

  if (indice >= 0 && indice < 64)
    matriz->setPixelColor(indice, color);
}

void limpiar()
{
  supIzq.clear();
  supCen.clear();
  supDer.clear();
  medIzq.clear();
  medCen.clear();
  medDer.clear();
  infCen.clear();
}

void mostrar()
{
  supIzq.show();
  supCen.show();
  supDer.show();
  medIzq.show();
  medCen.show();
  medDer.show();
  infCen.show();
}

void dibujarRango(int y, int izquierda, int derecha, uint32_t color)
{
  for (int x = izquierda; x <= derecha; x++)
  {
    pixel(x, y, color);
  }
}

void dibujarArbol()
{
  dibujarRango(4, 11, 13, verdeClaro);
  dibujarRango(5, 10, 14, verde);
  dibujarRango(6, 9, 15, verde);
  dibujarRango(7, 8, 16, verde);
  dibujarRango(8, 7, 17, verdeOscuro);
  dibujarRango(9, 6, 18, verde);
  dibujarRango(10, 5, 19, verde);
  dibujarRango(11, 4, 20, verdeOscuro);
  dibujarRango(12, 4, 20, verde);
  dibujarRango(13, 3, 21, verde);
  dibujarRango(14, 2, 22, verdeOscuro);
  dibujarRango(15, 1, 23, verde);

  for (int y = 16; y <= 22; y++)
  {
    dibujarRango(y, 10, 13, marron);
  }

  dibujarRango(23, 8, 15, marron);
}

void dibujarEstrella(bool brillante)
{
  uint32_t color;

  if (brillante)
    color = amarillo;
  else
    color = supIzq.Color(90, 55, 0);

  pixel(12, 0, color);
  pixel(11, 1, color);
  pixel(12, 1, color);
  pixel(13, 1, color);
  pixel(10, 2, color);
  pixel(11, 2, color);
  pixel(12, 2, color);
  pixel(13, 2, color);
  pixel(14, 2

More projects by svarasab