From 884afdbac778efbbd2c73249dd4af9f5362014ce Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Tue, 29 Jan 2019 10:47:52 +0100 Subject: [PATCH 1/3] New effects: - Added capability to display basic graphical frames --- effects.h | 35 +++++++++++++++++++++++++++++++- graphicsframe.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 graphicsframe.h diff --git a/effects.h b/effects.h index 78df7ae..c79a984 100644 --- a/effects.h +++ b/effects.h @@ -315,7 +315,6 @@ void scrollText(byte message, byte style, CRGB fgColor, CRGB bgColor) { } - void scrollTextZero() { scrollText(0, NORMAL, CRGB::Red, CRGB::Black); } @@ -328,3 +327,37 @@ void scrollTextTwo() { scrollText(2, NORMAL, CRGB::Green, CRGB(0,0,8)); } +void graphicsFrame(int frame){ + // Buffers for graphics generation + byte GlassesBits[kMatrixWidth][kMatrixHeight] = {{0}}; // 24 column x 8 row bit arrays (on/off frame) + int currentFrameAddress = pgm_read_word(&frameArray[frame]); + + // startup tasks + if (effectInit == false) { + effectInit = true; + effectDelay = 5; + } + + + for (byte x = 0; x < kMatrixWidth; x++) { + for (byte y = 0; y < kMatrixHeight; y++) { + GlassesBits[x][y] = pgm_read_byte(currentFrameAddress+x+kMatrixWidth*y); + if (GlassesBits[x][y] == 1) leds[XY(x, y)] = CRGB::White; + else leds[XY(x,y)] = CRGB::Black; + } + } +} + +void eyesAnim(){ + static byte frameSeq[] = {0,1,0,1,2,3,2,3}; + static byte frameIndex = 0; + // startup tasks + if (effectInit == false) { + effectInit = true; + effectDelay = 300; + } + graphicsFrame(frameSeq[frameIndex]); + frameIndex++; + frameIndex=frameIndex%8; +} + diff --git a/graphicsframe.h b/graphicsframe.h new file mode 100644 index 0000000..6394579 --- /dev/null +++ b/graphicsframe.h @@ -0,0 +1,54 @@ +// Full-frame bitmap graphic + +// Blinking Eyes +const byte frame0[5][16] PROGMEM = +{ + {0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0}, + {1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1}, + {1,0,0,0,1,0,1,0,0,1,0,0,0,1,0,1}, + {1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1}, + {0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0} +}; + +const byte frame1[5][16] PROGMEM = +{ + {0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0}, + {1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1}, + {1,0,1,0,0,0,1,0,0,1,0,1,0,0,0,1}, + {1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1}, + {0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0} +}; + +const byte frame2[5][16] PROGMEM = +{ + {0,1,1,1,1,1,1,0,0,1,1,1,1,1,1,0}, + {1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1}, + {1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1}, + {1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,1}, + {0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0} +}; +const byte frame3[5][16] PROGMEM = +{ + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, + {0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0}, + {0,0,1,0,1,0,0,0,0,0,0,1,0,1,0,0}, + {0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0}, + {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} +}; + +const byte * const frameArray[] PROGMEM = { + frame0[0], + frame1[0], + frame2[0], + frame3[0] +}; +/* +{ +{0b00000000, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, +{0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, +{0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b00000000, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, +{0b00000000, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000}, +{0b00000000, 0b00000000, 0b00000001, 0b00000001, 0b00000001, 0b00000001, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000} +}; +*/ + From 97e7ac994d384fa49c076b1f724f0b52a6e1082f Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Tue, 29 Jan 2019 10:50:40 +0100 Subject: [PATCH 2/3] Eyes animation added to the demo --- RGBShades.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RGBShades.ino b/RGBShades.ino index dcace47..2474aa1 100644 --- a/RGBShades.ino +++ b/RGBShades.ino @@ -54,6 +54,7 @@ #include #include #include "messages.h" +#include "graphicsframe.h" #include "font.h" #include "XYmap.h" #include "utils.h" @@ -73,7 +74,8 @@ functionList effectList[] = {threeSine, slantBars, scrollTextTwo, colorFill, - sideRain + sideRain, + eyesAnim }; const byte numEffects = (sizeof(effectList)/sizeof(effectList[0])); From edc157a676dd3e055a5eba8b382cc574aa0925d3 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Tue, 29 Jan 2019 12:59:13 +0100 Subject: [PATCH 3/3] Added color parameters to function graphicsFrame and color effect to eyeAnim --- effects.h | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/effects.h b/effects.h index c79a984..8397fe7 100644 --- a/effects.h +++ b/effects.h @@ -327,7 +327,7 @@ void scrollTextTwo() { scrollText(2, NORMAL, CRGB::Green, CRGB(0,0,8)); } -void graphicsFrame(int frame){ +void graphicsFrame(int frame, CRGB fgColor,CRGB bgColor){ // Buffers for graphics generation byte GlassesBits[kMatrixWidth][kMatrixHeight] = {{0}}; // 24 column x 8 row bit arrays (on/off frame) int currentFrameAddress = pgm_read_word(&frameArray[frame]); @@ -342,22 +342,32 @@ void graphicsFrame(int frame){ for (byte x = 0; x < kMatrixWidth; x++) { for (byte y = 0; y < kMatrixHeight; y++) { GlassesBits[x][y] = pgm_read_byte(currentFrameAddress+x+kMatrixWidth*y); - if (GlassesBits[x][y] == 1) leds[XY(x, y)] = CRGB::White; - else leds[XY(x,y)] = CRGB::Black; + if (GlassesBits[x][y] == 1) leds[XY(x, y)] = fgColor; + else leds[XY(x,y)] = bgColor; } } } void eyesAnim(){ - static byte frameSeq[] = {0,1,0,1,2,3,2,3}; + static byte frameSeq[] = {0,2,1,2,0,2,3,2,3,2}; static byte frameIndex = 0; + static unsigned long lastFrame=0; + const byte frameDelay=500; + // startup tasks if (effectInit == false) { effectInit = true; - effectDelay = 300; + effectDelay = 5; } - graphicsFrame(frameSeq[frameIndex]); - frameIndex++; - frameIndex=frameIndex%8; + + if (millis() > lastFrame+frameDelay) { + frameIndex++; + frameIndex=frameIndex%10; + lastFrame=millis(); + } + + CRGB fgColor = CHSV(cycleHue, 255, 255); + //CRGB bgColor = CHSV(cycleHue+128, 255, 255); + graphicsFrame(frameSeq[frameIndex],fgColor,CRGB::Black); }