From 14c34b47d4549f4f5229200eefb124d61bec3432 Mon Sep 17 00:00:00 2001 From: Vladimir Garistov Date: Sat, 2 Oct 2021 16:51:36 +0300 Subject: [PATCH] Added an example for a big RGB LED matrix --- Examples/Big_LED_strip/Big_LED_strip.ino | 164 +++++++++++++++++++++++ Examples/Big_LED_strip/elsys.ppm | Bin 0 -> 780 bytes 2 files changed, 164 insertions(+) create mode 100644 Examples/Big_LED_strip/Big_LED_strip.ino create mode 100644 Examples/Big_LED_strip/elsys.ppm diff --git a/Examples/Big_LED_strip/Big_LED_strip.ino b/Examples/Big_LED_strip/Big_LED_strip.ino new file mode 100644 index 0000000..168afe7 --- /dev/null +++ b/Examples/Big_LED_strip/Big_LED_strip.ino @@ -0,0 +1,164 @@ +#include +#include + +#define LED_PIN 12 +#define ROWS 8 +#define COLS 32 +#define NUM_PIXELS (ROWS * COLS) +#define PPM_HEADER_LENGHT 12 +#define BIG_IMAGE_FILE_SIZE 780 +#define DIMM 4 + +#define NEOPIXEL_ATE_MY_RAM + +int render_image(uint8_t buff[ROWS][COLS][3], const uint8_t image[]); +int display_rgb(uint8_t buff[ROWS][COLS][3]); +int display_rgb_direct(const uint8_t image[]); + +static const uint8_t big_image_data[BIG_IMAGE_FILE_SIZE] = +{ + 0x50, 0x36, 0x0a, 0x33, 0x32, 0x20, 0x38, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, + 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, + 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, + 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, + 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, + 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, + 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, + 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, + 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, + 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, + 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, + 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x00, 0x00, + 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, + 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, + 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, + 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, + 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x96, 0xf3, 0x21, 0x96, + 0xf3, 0x21, 0x96, 0xf3, 0x21, 0x96, 0xf3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xd5, 0x00, 0x00, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +Adafruit_NeoPixel led_matrix(NUM_PIXELS, LED_PIN, NEO_GRB); + +void setup() +{ + pinMode(LED_PIN, OUTPUT); + led_matrix.begin(); +} + +void loop() +{ + uint8_t frame_buffer[ROWS][COLS][3] = {{{0}}}; + + #ifdef NEOPIXEL_ATE_MY_RAM + render_image(frame_buffer, big_image_data); + display_rgb(frame_buffer); + #else + display_rgb_direct(big_image_data); + #endif +} + +int render_image(uint8_t buff[ROWS][COLS][3], const uint8_t image[]) +{ + if (buff == NULL || image == NULL) + return -1; + + for (uint8_t row = 0; row < ROWS; row++) + { + for (uint8_t col = 0; col < COLS; col++) + { + for (uint8_t i = 0; i < 3; i++) + { + buff[row][col][i] = image[PPM_HEADER_LENGHT + row * COLS * 3 + col * 3 + i]; + } + } + } + + return 0; +} + +int display_rgb(uint8_t buff[ROWS][COLS][3]) +{ + if (buff == NULL) + return -1; + + for (uint8_t col = 0; col < COLS; col += 2) + { + for (uint8_t row = 0; row < ROWS; row++) + { + led_matrix.setPixelColor(col * ROWS + row, led_matrix.Color(buff[row][col][0] / DIMM, + buff[row][col][1] / DIMM, + buff[row][col][2] / DIMM)); + } + } + for (uint8_t col = 1; col < COLS; col += 2) + { + for (uint8_t row = 0; row < ROWS; row++) + { + led_matrix.setPixelColor((col + 1) * ROWS - row - 1, led_matrix.Color(buff[row][col][0] / DIMM, + buff[row][col][1] / DIMM, + buff[row][col][2] / DIMM)); + } + } + led_matrix.show(); + + return 0; +} + +int display_rgb_direct(const uint8_t image[]) +{ + if (image == NULL) + return -1; + + for (uint8_t col = 0; col < COLS; col += 2) + { + for (uint8_t row = 0; row < ROWS; row++) + { + led_matrix.setPixelColor(col * ROWS + row, led_matrix.Color(image[PPM_HEADER_LENGHT + row * COLS * 3 + col * 3] / DIMM, + image[PPM_HEADER_LENGHT + row * COLS * 3 + col * 3 + 1] / DIMM, + image[PPM_HEADER_LENGHT + row * COLS * 3 + col * 3 + 2] / DIMM)); + } + } + for (uint8_t col = 1; col < COLS; col += 2) + { + for (uint8_t row = 0; row < ROWS; row++) + { + led_matrix.setPixelColor((col + 1) * ROWS - row - 1, led_matrix.Color(image[PPM_HEADER_LENGHT + row * COLS * 3 + col * 3] / DIMM, + image[PPM_HEADER_LENGHT + row * COLS * 3 + col * 3 + 1] / DIMM, + image[PPM_HEADER_LENGHT + row * COLS * 3 + col * 3 + 2] / DIMM)); + } + } + led_matrix.show(); + + return 0; +} diff --git a/Examples/Big_LED_strip/elsys.ppm b/Examples/Big_LED_strip/elsys.ppm new file mode 100644 index 0000000000000000000000000000000000000000..f7381c3c46dc9dd116ec0c9d61c667a93fdd31a5 GIT binary patch literal 780 zcmdUo%L#x$3`9Mr3T!+XQm=O8L=ZEC^ETfnczM~u@lnx#AHu{F-8dJ SC)MjH8mOyY0!66*`~Lvx{Be8$ literal 0 HcmV?d00001 -- 2.39.5