#include #include "xtensa/core-macros.h" #include #include "main.h" #include "caveatbrush9pt7b.h" #include "overlay.h" #define R1 42 #define G1 40 #define BL1 41 #define R2 38 #define G2 37 #define BL2 39 #define CH_A 45 #define CH_B 36 #define CH_C 48 #define CH_D 35 #define CH_E 21 #define CLK 2 #define LAT 47 #define OE 14 #define PIN_E 21 #define PANEL_WIDTH 64 #define PANEL_HEIGHT 32 // Panel height of 64 will required PIN_E to be defined. #define PANELS_NUMBER 1 #define PANE_WIDTH PANEL_WIDTH * PANELS_NUMBER #define PANE_HEIGHT PANEL_HEIGHT #define NUM_LEDS PANE_WIDTH*PANE_HEIGHT #define ONBOARD_LED 13 MatrixPanel_I2S_DMA *matrix = nullptr; int line_pos[PANEL_WIDTH]; // where a rain marker is (y coordinate) int line_length[PANEL_WIDTH]; // how long a line is for a given x coord int line_speed[PANEL_WIDTH]; // how fast each line moves unsigned long line_last_moved[PANEL_WIDTH]; typedef struct { bool reached_bottom = false; int y; int length; int speed; unsigned long last_moved; } Raindrop; Raindrop raindrops[PANEL_WIDTH]; void setup(){ Serial.begin(BAUD_RATE); pinMode(ONBOARD_LED, OUTPUT); for (int i = 0; ibegin(); matrix->setBrightness8(64); matrix->fillScreenRGB888(0, 0, 0); matrix->setFont(&CaveatBrush_Regular9pt7b); } void loop() { matrix ->flipDMABuffer(); matrix->clearScreen(); delay(25); //matrix ->drawBitmap(0, 0, overlay, 64, 32, matrix->color565(64, 0, 0)); unsigned long timestamp = millis(); for (int x = 0; x < PANEL_WIDTH; x++) { if ((timestamp - raindrops[x].last_moved) > raindrops[x].speed) { // step down a pixel raindrops[x].y++; raindrops[x].last_moved = timestamp; } if (raindrops[x].y > PANEL_HEIGHT) { raindrops[x].y = 0; raindrops[x].reached_bottom = true; } if (raindrops[x].y >= 0) { //draw our pixel matrix->drawPixel(x, raindrops[x].y, matrix->color565(128, 255, 128)); // draw our trail for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) { int trail_y = raindrops[x].y - trail_offset; if (trail_y >= 0) { int pixel_num = (trail_y * PANEL_WIDTH) + x; if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) )) { matrix->drawPixel(x, trail_y, matrix->color565(128, 255, 128)); } else { matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0)); } } else if (raindrops[x].reached_bottom) { int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x; if (line_pos[x] >= 0) { if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) )) { matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(128, 255, 128)); } else { matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0)); } } else { break; } } } } } }