#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
#include <FastLED.h>
#define R1 25
#define G1 26
#define BL1 27
#define R2 14
#define G2 12
#define BL2 13
#define CH_A 23
#define CH_B 19
#define CH_C 5
#define CH_D 17
#define CH_E 32 // Pin necesario para 64x64 panel
#define CLK 16
#define LAT 4
#define OE 15
#define PANEL_WIDTH 64
#define PANEL_HEIGHT 64
#define PANELS_NUMBER 1
#define PANE_WIDTH PANEL_WIDTH * PANELS_NUMBER
#define PANE_HEIGHT PANEL_HEIGHT
MatrixPanel_I2S_DMA *dma_display = nullptr;
uint16_t time_counter = 0, cycles = 0, fps = 0;
unsigned long fps_timer;
CRGB currentColor;
CRGBPalette16 palettes[] = {HeatColors_p, LavaColors_p, RainbowColors_p, RainbowStripeColors_p, CloudColors_p};
CRGBPalette16 currentPalette = palettes[0];
CRGB ColorFromCurrentPalette(uint8_t index = 0, uint8_t brightness = 255, TBlendType blendType = LINEARBLEND) {
return ColorFromPalette(currentPalette, index, brightness, blendType);
}
void setup() {
Serial.begin(115200);
Serial.println(F("*****************************************************"));
Serial.println(F("* ESP32-HUB75-MatrixPanel-I2S-DMA DEMO *"));
Serial.println(F("*****************************************************"));
HUB75_I2S_CFG mxconfig;
mxconfig.mx_height = PANEL_HEIGHT;
mxconfig.chain_length = PANELS_NUMBER;
mxconfig.gpio.e = CH_E;
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->setBrightness8(255);
if(!dma_display->begin()) {
Serial.println("****** !KABOOM! I2S memory allocation failed ***********");
}
Serial.println("Fill screen: RED");
dma_display->fillScreenRGB888(255, 0, 0);
delay(1000);
Serial.println("Fill screen: GREEN");
dma_display->fillScreenRGB888(0, 255, 0);
delay(1000);
Serial.println("Fill screen: BLUE");
dma_display->fillScreenRGB888(0, 0, 255);
delay(1000);
Serial.println("Fill screen: Neutral White");
dma_display->fillScreenRGB888(64, 64, 64);
delay(1000);
Serial.println("Fill screen: black");
dma_display->fillScreenRGB888(0, 0, 0);
delay(1000);
currentPalette = RainbowColors_p;
Serial.println("Starting plasma effect...");
fps_timer = millis();
}
void loop() {
for (int x = 0; x < PANE_WIDTH; x++) {
for (int y = 0; y < PANE_HEIGHT; y++) {
int16_t v = 128;
uint8_t wibble = sin8(time_counter);
v += sin16(x * wibble * 3 + time_counter);
v += cos16(y * (128 - wibble) + time_counter);
v += sin16(y * x * cos8(-time_counter) / 8);
currentColor = ColorFromPalette(currentPalette, (v >> 8));
dma_display->drawPixelRGB888(x, y, currentColor.r, currentColor.g, currentColor.b);
}
}
++time_counter;
++cycles;
++fps;
if (cycles >= 1024) {
time_counter = 0;
cycles = 0;
currentPalette = palettes[random(0,sizeof(palettes)/sizeof(palettes[0]))];
}
if (fps_timer + 5000 < millis()){
Serial.printf_P(PSTR("Effect fps: %d\n"), fps/5);
fps_timer = millis();
fps = 0;
}
}