Browse Source

garland: add waves animation (#2430)

* Add anim_waves

* Minor fixes

Co-authored-by: Dmitry Blinov <dblinov@blackberry.com>
dev
DmitryBlinov 3 years ago
committed by GitHub
parent
commit
acfead4229
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 86 additions and 7 deletions
  1. +1
    -1
      code/espurna/garland.cpp
  2. +3
    -3
      code/espurna/garland/anim.h
  3. +1
    -1
      code/espurna/garland/animations/anim_glow.h
  4. +55
    -0
      code/espurna/garland/animations/anim_waves.h
  5. +25
    -2
      code/espurna/garland/color.h
  6. +1
    -0
      code/espurna/garland/scene.h

+ 1
- 1
code/espurna/garland.cpp View File

@ -139,7 +139,7 @@ Adafruit_NeoPixel pixels = Adafruit_NeoPixel(GARLAND_LEDS, GARLAND_D_PIN, NEO_GR
Scene scene(&pixels);
Anim* anims[] = {new AnimGlow(), new AnimStart(), new AnimPixieDust(), new AnimSparkr(), new AnimRun(), new AnimStars(), new AnimSpread(),
new AnimRandCyc(), new AnimFly(), new AnimComets(), new AnimAssemble(), new AnimDolphins(), new AnimSalut(), new AnimFountain()};
new AnimRandCyc(), new AnimFly(), new AnimComets(), new AnimAssemble(), new AnimDolphins(), new AnimSalut(), new AnimFountain(), new AnimWaves()};
constexpr size_t animsSize() { return sizeof(anims)/sizeof(anims[0]); }


+ 3
- 3
code/espurna/garland/anim.h View File

@ -37,11 +37,11 @@ protected:
int inc;
//brigthness animation (BrA) current initial phase
byte braPhase;
byte braPhase = 0;
//braPhase change speed
byte braPhaseSpd = 5;
byte braPhaseSpd = 8;
//BrA frequency (spatial)
byte braFreq = 150;
byte braFreq = 40;
Color curColor = Color(0);
Color prevColor = Color(0);


+ 1
- 1
code/espurna/garland/animations/anim_glow.h View File

@ -22,7 +22,7 @@ class AnimGlow : public Anim {
glowForEachLed(i);
}
} else {
for (int i = 0; i < numLeds; ++i) {
for (int i = numLeds - 1 ; i >= 0; --i) {
leds[i] = curColor;
glowForEachLed(i);
}


+ 55
- 0
code/espurna/garland/animations/anim_waves.h View File

@ -0,0 +1,55 @@
#if GARLAND_SUPPORT
#include "../anim.h"
#include "../palette.h"
//------------------------------------------------------------------------------
class AnimWaves : public Anim {
private:
int bra_phase;
int bra_phase_speed;
byte bra_speed;
byte bra_min;
int sign;
public:
AnimWaves() : Anim("Waves") {
}
void SetupImpl() override {
curColor = palette->getRndInterpColor().max_bright();
glowSetUp();
sign = braPhaseSpd > 128 ? -1 : 1;
bra_phase = secureRandom(255);
bra_phase_speed = secureRandom(2, 5);
bra_speed = secureRandom(4, 12);
bra_min = secureRandom(20, 30);
}
void Run() override {
int bra = bra_phase;
int8_t bra_inc = -sign * bra_speed;
for (int i = 0; i < numLeds; ++i) {
leds[i] = curColor;
glowForEachLed(i);
leds[i] = leds[i].brightness((byte)bra);
bra += bra_inc;
if (bra > 255 || bra < bra_min) {
bra_inc = -bra_inc;
bra = bra > 255 ? 255 : bra_min;
}
}
glowRun();
bra_phase += bra_phase_speed;
if (bra_phase > 255 || bra_phase < bra_min) {
bra_phase_speed = -bra_phase_speed;
sign = -sign;
bra_phase = bra_phase > 255 ? 255 : bra_min;
}
}
};
#endif // GARLAND_SUPPORT

+ 25
- 2
code/espurna/garland/color.h View File

@ -10,6 +10,7 @@ Inspired by https://github.com/Vasil-Pahomov/ArWs2812 (currently https://github.
#if GARLAND_SUPPORT
#include <Arduino.h>
#include <string>
struct Color
{
@ -47,19 +48,35 @@ struct Color
}
//fades (decreases all RGB channels brightness) this color by k
void fade(byte k) {
Color& fade(byte k) {
if (r>=k) { r=r-k; } else { r=0; }
if (g>=k) { g=g-k; } else { g=0; }
if (b>=k) { b=b-k; } else { b=0; }
return *this;
}
//fades color separately for each channel
void fade3(byte dr, byte dg, byte db) {
Color& fade3(byte dr, byte dg, byte db) {
if (r>=dr) { r=r-dr; } else { r=0; }
if (g>=dg) { g=g-dg; } else { g=0; }
if (b>=db) { b=b-db; } else { b=0; }
return *this;
}
Color max_bright() {
if (r==255 || g==255 || b==255)
return Color(r, g, b);
double kr = 255.0/r;
double kg = 255.0/g;
double kb = 255.0/b;
double k1 = kr < kg ? kr : kg;
double k2 = k1 < kb ? k1 : kb;
int r0 = r * k2;
int g0 = g * k2;
int b0 = b * k2;
return Color(r0, g0, b0);
}
//checks whether this color is visually close to given one
bool isCloseTo(Color c) const {
int diff = abs(r - c.r) + abs(g - c.g) + abs(b - c.b);
@ -81,6 +98,12 @@ struct Color
Serial.print(("b="));Serial.println(b);
}
String to_str() {
char buf[20];
sprintf(buf, "r=%hhu, g=%hhu, b=%hhu", r, g, b);
return buf;
}
friend bool operator== (const Color &c1, const Color &c2);
};


+ 1
- 0
code/espurna/garland/scene.h View File

@ -27,6 +27,7 @@ Inspired by https://github.com/Vasil-Pahomov/ArWs2812 (currently https://github.
#include "animations/anim_spread.h"
#include "animations/anim_stars.h"
#include "animations/anim_start.h"
#include "animations/anim_waves.h"
class Adafruit_NeoPixel;
class Palette;


Loading…
Cancel
Save