From 4a6f4a4eb8009bc05e496a2af8d600cb7ae948f5 Mon Sep 17 00:00:00 2001 From: Commander1024 Date: Mon, 4 Feb 2019 11:39:29 +0100 Subject: [PATCH] Added additional animations. --- flame.ino | 128 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 118 insertions(+), 10 deletions(-) diff --git a/flame.ino b/flame.ino index 58b69f1..152163c 100644 --- a/flame.ino +++ b/flame.ino @@ -9,14 +9,14 @@ #define MAX(x, y) ((x) > (y) ? (x) : (y)) #define PIN_BUTTON 3 // Input pin für Button -#define PIN_LED 2 // Output pin für Led-Strip -#define NUM_PIXELS (5 * 64) +#define PIN_LED 6 // Output pin für Led-Strip +#define NUM_PIXELS (5 * 60) -#define NUM_MODES 6 +#define NUM_MODES 8 // Framebuffer-Dimensions. Depends on the tube radius -#define FLAME_WIDTH 12 -#define FLAME_HEIGHT 27 +#define FLAME_WIDTH 10 +#define FLAME_HEIGHT 30 // Intensity buffer for flames and sparks static uint16_t flamebuffer[FLAME_HEIGHT][FLAME_WIDTH] = { { 0, }, }; @@ -90,7 +90,6 @@ render_blueyellow (const uint16_t t) { uint16_t i; uint8_t pos; - for (i = 0; i < NUM_PIXELS; i++) { pos = (t + i) % 64; @@ -101,6 +100,22 @@ render_blueyellow (const uint16_t t) } } +void +render_orangewhite (const uint16_t t) + +// This is a copy of render_blueyellow with colors changed to C1024 orange and white +{ + uint16_t i; + uint8_t pos; + for (i = 0; i < NUM_PIXELS; i++) + { + pos = (t + i) % 64; + if (pos < 32) + pixels.setPixelColor (i, 255, 200, 200); + else + pixels.setPixelColor (i, 192, 72, 11); + } +} void render_rainbow (const uint16_t t) @@ -195,6 +210,7 @@ render_rgbsparks (const uint16_t t) flamebuffer[y][x] = rand() % (255 * 3); for (y = FLAME_HEIGHT; y > 0; ) + { y--; @@ -217,7 +233,7 @@ render_rgbsparks (const uint16_t t) } // Deal with multiples of three, this ensures the same base color - // the condition here is false always, if enabed this makes the + // the condition here is false always, if enabled this makes the // colorful sparks go up. if (t % 6 == 7) { @@ -235,6 +251,82 @@ render_rgbsparks (const uint16_t t) } +void +render_whitesparks (const uint16_t t) +{ + uint8_t x, y; + + // This is the blatantly bad copy of render_rgbparks but does what I want ¯\_(ツ)_/¯ + + x = rand() % FLAME_WIDTH; + y = rand() % FLAME_HEIGHT; + flamebuffer[y][x] = rand() % (255 * 3); + + for (y = FLAME_HEIGHT; y > 0; ) + + { + y--; + + for (x = 0; x < FLAME_WIDTH; x++) + { + switch (flamebuffer[y][x] % 3) + { + case 0: + pixels.setPixelColor (y * FLAME_WIDTH + x, + glut[flamebuffer[y][x] / 3], glut[flamebuffer[y][x] / 3], glut[flamebuffer[y][x] / 3]); + break; + case 1: + pixels.setPixelColor (y * FLAME_WIDTH + x, + glut[flamebuffer[y][x] / 3], glut[flamebuffer[y][x] / 3], glut[flamebuffer[y][x] / 3]); + break; + case 2: + pixels.setPixelColor (y * FLAME_WIDTH + x, + glut[flamebuffer[y][x] / 3], glut[flamebuffer[y][x] / 3], glut[flamebuffer[y][x] / 3]); + break; + } + + // the condition here is false always, if enabled this makes the + // white sparks go up. + if (t % 6 == 7) + { + if (y > 1) + flamebuffer[y][x] = MAX (9, flamebuffer[y-1][x]) - 9; + else + flamebuffer[y][x] = 0; + } + else + { + flamebuffer[y][x] = MAX (9, flamebuffer[y][x]) - 9; + } + } + } +} + + +void +render_orangepulse (const uint16_t t) + +// This is a C1024 orange full-torch glow effect +{ + uint16_t i; + uint8_t pos; +// uint8_t +// for (i = 0; i < NUM_PIXELS; i++) +// { +// pos = (t + i) % 64; +// if (pos < 32) +// pixels.setPixelColor (i, 255, 200, 200); +// else +// pixels.setPixelColor (i, 192, 72, 11); +// } + for (i = 0; i < NUM_PIXELS; i++) + { + pixels.setPixelColor (i, 195, 72, 11); + } + +} + + // Arduino init. void @@ -349,25 +441,41 @@ loop () break; case 2: - render_rainbow (t); + render_orangewhite (t); delay_value = 10; break; case 3: - render_redblue (t); + render_rainbow (t); delay_value = 10; break; case 4: + render_redblue (t); + delay_value = 10; + break; + + case 5: render_kitt (t); delay_value = 20; break; - case 5: + case 6: render_rgbsparks (t); delay_value = 10; break; + case 7: + render_whitesparks (t); + delay_value = 10; + break; + +// Inactive for now due to RENDER_MODES: + case 8: + render_orangepulse (t); + delay_value = 10; + break; + default: render_flame (); break;