Permalink
Browse files

New effect: Color chase

  • Loading branch information...
noniq committed Dec 9, 2017
1 parent e4e7be2 commit bae11c5e53f3fc84fd207cf0de0a07d98602c262
Showing with 41 additions and 4 deletions.
  1. +40 −4 Effects.cpp
  2. +1 −0 Effects.h
@@ -14,14 +14,17 @@ void Effects::doEffect(uint8_t effect, Rotary::Action action) {
case 1:
scroll(ms, action);
break;
case 5:
knightRider(ms);
case 2:
makeRainbow(effect != lastEffect, ms, action);
break;
case 3:
blink(effect != lastEffect, action);
break;
case 2:
makeRainbow(effect != lastEffect, ms, action);
case 4:
colorChase(ms, action);
break;
case 5:
knightRider(ms);
break;
default:
break;
@@ -153,3 +156,36 @@ void Effects::makeRainbow(boolean firstTime, uint32_t ms, Rotary::Action action)
break;
}
}
void Effects::colorChase(uint32_t ms, Rotary::Action action) {
static constexpr uint8_t DELAY_MS = 200;
static constexpr uint8_t COLOR_STEPS = 6;
static uint8_t step = 0;
static uint8_t colorStep = 0;
if (ms > DELAY_MS) {
lastUpdate = millis();
if (step > 0) leds->mainStrip[step - 1] = 0;
if (step < LEDS_MAIN_STRIP_NUM_LEDS) {
leds->mainStrip[step].setHSV(255.0 / COLOR_STEPS * colorStep, 250, 200);
step++;
} else {
colorStep++;
if (colorStep >= COLOR_STEPS) colorStep = 0;
step = 0;
}
}
switch (action) {
case Rotary::LEFT:
if (step > 0) step--;
leds->scrollStripToLeft();
break;
case Rotary::RIGHT:
if (step < LEDS_MAIN_STRIP_NUM_LEDS) step++;
leds->scrollStripToRight();
break;
default:
break;
}
}
@@ -15,6 +15,7 @@ class Effects {
void knightRider(uint32_t ms);
void blink(boolean firstTime, Rotary::Action action);
void makeRainbow(boolean firstTime, uint32_t ms, Rotary::Action action);
void colorChase(uint32_t ms, Rotary::Action action);
LEDs *leds;
uint32_t lastUpdate = 0;

0 comments on commit bae11c5

Please sign in to comment.