From: vl_garistov Date: Mon, 19 Oct 2020 21:16:19 +0000 (+0300) Subject: added demo code for LED strips X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=854e8e3c595b41aee5252f1edb6d5d5f3d52a58a;p=vmks.git added demo code for LED strips --- diff --git a/TUES-LED_strip_1/TUES-LED_strip_1.ino b/TUES-LED_strip_1/TUES-LED_strip_1.ino new file mode 100644 index 0000000..2426e6a --- /dev/null +++ b/TUES-LED_strip_1/TUES-LED_strip_1.ino @@ -0,0 +1,132 @@ +#include +#include + +#define NUM_PIXELS 16 + +#define TOP_ROW 4 +#define MID_ROW 3 +#define BOT_ROW 2 + +#define PPM_HEADER_LENGHT 58 +#define IMAGE_FILE_LENGHT 202 + +/* +typedef enum {RED, GREEN, BLUE, YELLOW, MAGENTA, CYAN} simple_color_t; +int display_enum(simple_color_t buff[]); +*/ + +int render_image(uint8_t buff[3][NUM_PIXELS][3], const uint8_t image[]); +int display_rgb(uint8_t buff[3][NUM_PIXELS][3]); + +const uint8_t image_data_0[IMAGE_FILE_LENGHT] = +{ + 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, + 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31, + 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e, + 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0x78, 0x90, 0xbc, 0x7b, 0x93, + 0xbe, 0x7e, 0x98, 0xbe, 0x7e, 0x98, 0xbc, 0x7d, 0x98, 0xba, 0x7b, 0x96, 0xb8, 0x79, 0x96, 0xb4, + 0x75, 0x92, 0xb1, 0x72, 0x8f, 0xaf, 0x70, 0x8d, 0xab, 0x6c, 0x89, 0xa7, 0x68, 0x85, 0xa2, 0x61, + 0x7f, 0x9c, 0x5b, 0x79, 0x9a, 0x57, 0x76, 0x9b, 0x56, 0x75, 0xb8, 0x77, 0x8f, 0xbb, 0x7a, 0x92, + 0xbc, 0x7c, 0x96, 0xbc, 0x7c, 0x96, 0xbb, 0x7b, 0x96, 0xb9, 0x79, 0x94, 0xb5, 0x76, 0x91, 0xb2, + 0x73, 0x8e, 0xae, 0x6f, 0x8c, 0xac, 0x6d, 0x8a, 0xa4, 0x65, 0x82, 0xa0, 0x61, 0x7e, 0x9b, 0x5a, + 0x78, 0x96, 0x55, 0x73, 0x94, 0x51, 0x70, 0x97, 0x52, 0x71, 0xb9, 0x75, 0x8c, 0xba, 0x79, 0x91, + 0xbd, 0x7c, 0x94, 0xbb, 0x7b, 0x95, 0xba, 0x7a, 0x95, 0xb8, 0x78, 0x93, 0xb5, 0x75, 0x90, 0xb0, + 0x71, 0x8c, 0xad, 0x6e, 0x8b, 0xaa, 0x6b, 0x88, 0xa3, 0x64, 0x81, 0xa0, 0x5f, 0x7d, 0x9b, 0x5a, + 0x78, 0x97, 0x54, 0x73, 0x95, 0x52, 0x71, 0x99, 0x53, 0x75 +}; + +const uint8_t image_data_1[IMAGE_FILE_LENGHT] = +{ + 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, + 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31, + 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e, + 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0xa9, 0xd6, 0xb8, 0xa7, 0xd4, + 0xba, 0xaa, 0xd7, 0xbd, 0xac, 0xd9, 0xbc, 0xab, 0xd8, 0xbc, 0xab, 0xd7, 0xba, 0xa9, 0xd5, 0xb5, + 0xa4, 0xd0, 0xaf, 0x9e, 0xca, 0x98, 0x89, 0xb2, 0x8d, 0x7e, 0xa5, 0x7c, 0x6d, 0x94, 0x70, 0x62, + 0x86, 0x6b, 0x5d, 0x80, 0x6c, 0x5e, 0x81, 0x6e, 0x60, 0x81, 0xb9, 0xac, 0xd8, 0xc2, 0xb2, 0xdf, + 0xbe, 0xb1, 0xdd, 0xbd, 0xad, 0xda, 0xbb, 0xae, 0xda, 0xba, 0xad, 0xd9, 0xb7, 0xaa, 0xd6, 0xb2, + 0xa5, 0xd1, 0xae, 0xa1, 0xcc, 0x9d, 0x8e, 0xb7, 0x8f, 0x80, 0xa7, 0x80, 0x72, 0x96, 0x77, 0x69, + 0x8d, 0x72, 0x64, 0x87, 0x6e, 0x60, 0x83, 0x6c, 0x5e, 0x7f, 0xbe, 0xb1, 0xdd, 0xc4, 0xb7, 0xe3, + 0xc2, 0xb5, 0xe1, 0xc1, 0xb4, 0xe0, 0xc0, 0xb3, 0xdf, 0xbe, 0xb3, 0xde, 0xbb, 0xb0, 0xdb, 0xb7, + 0xac, 0xd7, 0xb3, 0xa8, 0xd2, 0xa0, 0x91, 0xba, 0x93, 0x84, 0xab, 0x83, 0x75, 0x99, 0x78, 0x6a, + 0x8e, 0x72, 0x64, 0x87, 0x6d, 0x5f, 0x82, 0x6b, 0x5d, 0x7e +}; + +const uint8_t image_data_2[] = +{ + 0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, + 0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31, + 0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e, + 0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a, + 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x1f, 0xee, 0x1d, 0x00, 0x00, + 0x00, 0x1f, 0xee, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x04, 0x04, 0x04, + 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a, + 0x0a, 0xfe, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, + 0x00, 0x00, 0x00, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0x1a, + 0x0a, 0xfe, 0x1a, 0x0a, 0xfe, 0x00, 0x00, 0x00, 0xdd, 0xfa, 0x03, 0xdd, 0xfa, 0x03, 0xdd, 0xfa, + 0x03, 0xdd, 0xfa, 0x03, 0xdd, 0xfa, 0x03, 0x00, 0x00, 0x00 +}; + +Adafruit_NeoPixel top_row(NUM_PIXELS, TOP_ROW, NEO_GRB); +Adafruit_NeoPixel mid_row(NUM_PIXELS, MID_ROW, NEO_GRB); +Adafruit_NeoPixel bot_row(NUM_PIXELS, BOT_ROW, NEO_GRB); + +void setup() +{ + pinMode(TOP_ROW, OUTPUT); + pinMode(MID_ROW, OUTPUT); + pinMode(BOT_ROW, OUTPUT); + + // LED strip initialization + top_row.begin(); + mid_row.begin(); + bot_row.begin(); +} + +void loop() +{ + uint8_t frame_buffer[3][NUM_PIXELS][3] = {{{0}}}; + + render_image(frame_buffer, image_data_2); + display_rgb(frame_buffer); +} + +int render_image(uint8_t buff[3][NUM_PIXELS][3], const uint8_t image[]) +{ + if (buff == NULL || image == NULL) + return -1; + + for (uint8_t row = 0; row < 3; row++) + { + for (uint8_t col = 0; col < NUM_PIXELS; col++) + { + for (uint8_t i = 0; i < 3; i++) + { + buff[row][col][i] = image[PPM_HEADER_LENGHT + row * NUM_PIXELS * 3 + col * 3 + i]; + } + } + } + + return 0; +} + +int display_rgb(uint8_t buff[3][NUM_PIXELS][3]) +{ + if (buff == NULL) + return -1; + + for (uint8_t col; col < NUM_PIXELS; col++) + { + top_row.setPixelColor(col, top_row.Color(buff[0][col][0], buff[0][col][1], buff[0][col][2])); + mid_row.setPixelColor(col, mid_row.Color(buff[1][col][0], buff[1][col][1], buff[1][col][2])); + bot_row.setPixelColor(col, bot_row.Color(buff[2][col][0], buff[2][col][1], buff[2][col][2])); + } + + top_row.show(); + mid_row.show(); + bot_row.show(); + + return 0; +} diff --git a/TUES-LED_strip_1/mona_lisa.ppm b/TUES-LED_strip_1/mona_lisa.ppm new file mode 100644 index 0000000..2be5d2a Binary files /dev/null and b/TUES-LED_strip_1/mona_lisa.ppm differ diff --git a/TUES-LED_strip_1/nozdra.ppm b/TUES-LED_strip_1/nozdra.ppm new file mode 100644 index 0000000..dbbd1b3 --- /dev/null +++ b/TUES-LED_strip_1/nozdra.ppm @@ -0,0 +1,5 @@ +P6 +# Created by GIMP version 2.10.22 PNM plug-in +16 3 +255 +¹x¼{“¾~˜¾~˜¼}˜º{–¸y–´u’±r¯p«l‰§h…¢aœ[yšWv›Vu¸w»z’¼|–¼|–»{–¹y”µv‘²sŽ®oŒ¬mŠ¤e‚ a~›Zx–Us”Qp—Rq¹uŒºy‘½|”»{•ºz•¸x“µu°qŒ­n‹ªkˆ£d _}›Zx—Ts•Rq™Su \ No newline at end of file diff --git a/TUES-LED_strip_1/rick_astley.jpg b/TUES-LED_strip_1/rick_astley.jpg new file mode 100644 index 0000000..fd8e530 Binary files /dev/null and b/TUES-LED_strip_1/rick_astley.jpg differ diff --git a/TUES-LED_strip_1/sako.ppm.txt b/TUES-LED_strip_1/sako.ppm.txt new file mode 100644 index 0000000..c3967d2 --- /dev/null +++ b/TUES-LED_strip_1/sako.ppm.txt @@ -0,0 +1,13 @@ +0x50, 0x36, 0x0a, 0x23, 0x20, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, +0x47, 0x49, 0x4d, 0x50, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x32, 0x2e, 0x31, +0x30, 0x2e, 0x32, 0x32, 0x20, 0x50, 0x4e, 0x4d, 0x20, 0x70, 0x6c, 0x75, 0x67, 0x2d, 0x69, 0x6e, +0x0a, 0x31, 0x36, 0x20, 0x33, 0x0a, 0x32, 0x35, 0x35, 0x0a, 0xb9, 0xa9, 0xd6, 0xb8, 0xa7, 0xd4, +0xba, 0xaa, 0xd7, 0xbd, 0xac, 0xd9, 0xbc, 0xab, 0xd8, 0xbc, 0xab, 0xd7, 0xba, 0xa9, 0xd5, 0xb5, +0xa4, 0xd0, 0xaf, 0x9e, 0xca, 0x98, 0x89, 0xb2, 0x8d, 0x7e, 0xa5, 0x7c, 0x6d, 0x94, 0x70, 0x62, +0x86, 0x6b, 0x5d, 0x80, 0x6c, 0x5e, 0x81, 0x6e, 0x60, 0x81, 0xb9, 0xac, 0xd8, 0xc2, 0xb2, 0xdf, +0xbe, 0xb1, 0xdd, 0xbd, 0xad, 0xda, 0xbb, 0xae, 0xda, 0xba, 0xad, 0xd9, 0xb7, 0xaa, 0xd6, 0xb2, +0xa5, 0xd1, 0xae, 0xa1, 0xcc, 0x9d, 0x8e, 0xb7, 0x8f, 0x80, 0xa7, 0x80, 0x72, 0x96, 0x77, 0x69, +0x8d, 0x72, 0x64, 0x87, 0x6e, 0x60, 0x83, 0x6c, 0x5e, 0x7f, 0xbe, 0xb1, 0xdd, 0xc4, 0xb7, 0xe3, +0xc2, 0xb5, 0xe1, 0xc1, 0xb4, 0xe0, 0xc0, 0xb3, 0xdf, 0xbe, 0xb3, 0xde, 0xbb, 0xb0, 0xdb, 0xb7, +0xac, 0xd7, 0xb3, 0xa8, 0xd2, 0xa0, 0x91, 0xba, 0x93, 0x84, 0xab, 0x83, 0x75, 0x99, 0x78, 0x6a, +0x8e, 0x72, 0x64, 0x87, 0x6d, 0x5f, 0x82, 0x6b, 0x5d, 0x7e \ No newline at end of file