]> kolegite.com Git - vmks.git/commitdiff
Added an example for a big RGB LED matrix
authorVladimir Garistov <vl.garistov@gmail.com>
Sat, 2 Oct 2021 13:51:36 +0000 (16:51 +0300)
committerVladimir Garistov <vl.garistov@gmail.com>
Sat, 2 Oct 2021 13:51:36 +0000 (16:51 +0300)
Examples/Big_LED_strip/Big_LED_strip.ino [new file with mode: 0644]
Examples/Big_LED_strip/elsys.ppm [new file with mode: 0644]

diff --git a/Examples/Big_LED_strip/Big_LED_strip.ino b/Examples/Big_LED_strip/Big_LED_strip.ino
new file mode 100644 (file)
index 0000000..168afe7
--- /dev/null
@@ -0,0 +1,164 @@
+#include <Adafruit_NeoPixel.h>
+#include <inttypes.h>
+
+#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 (file)
index 0000000..f7381c3
Binary files /dev/null and b/Examples/Big_LED_strip/elsys.ppm differ