Permalink
Browse files

New effect: leftRightColorFade

  • Loading branch information...
noniq committed Dec 9, 2017
1 parent bae11c5 commit c71e79407caf5bc729d455c44f9f8a514c6243b5
Showing with 46 additions and 0 deletions.
  1. +45 −0 Effects.cpp
  2. +1 −0 Effects.h
@@ -26,6 +26,8 @@ void Effects::doEffect(uint8_t effect, Rotary::Action action) {
case 5:
knightRider(ms);
break;
case 6:
leftRightColorFade(ms, action);
default:
break;
}
@@ -189,3 +191,46 @@ void Effects::colorChase(uint32_t ms, Rotary::Action action) {
break;
}
}
void Effects::leftRightColorFade(uint32_t ms, Rotary::Action action) {
static constexpr uint8_t DELAY_MS = 50;
static constexpr uint8_t COLOR_STEPS = 8;
static uint8_t center = LEDS_MAIN_STRIP_NUM_LEDS / 2;
static uint8_t step = 0;
static uint8_t colorStep = 0;
static boolean turnOff = false;
if (ms > DELAY_MS) {
lastUpdate = millis();
for (uint8_t i = 0; i < step; i++) {
if (i <= center) {
leds->mainStrip[center - i].setHSV(255.0 / COLOR_STEPS * colorStep, 200, turnOff ? 0 : 200);
}
if (center + i < LEDS_MAIN_STRIP_NUM_LEDS) {
leds->mainStrip[center + i].setHSV(255.0 / COLOR_STEPS * colorStep, 200, turnOff ? 0 : 200);
}
}
leds->mainStrip[center].setHSV(0, 0, 200);
if (step > center && center + step >= LEDS_MAIN_STRIP_NUM_LEDS) {
step = 0;
if (turnOff) {
colorStep++;
if (colorStep == COLOR_STEPS) colorStep = 0;
}
turnOff = !turnOff;
} else {
step++;
}
}
switch (action) {
case Rotary::LEFT:
if (center > 5) center--;
break;
case Rotary::RIGHT:
if (center < 9) center++;
break;
default:
break;
}
}
@@ -16,6 +16,7 @@ class Effects {
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);
void leftRightColorFade(uint32_t ms, Rotary::Action action);
LEDs *leds;
uint32_t lastUpdate = 0;

0 comments on commit c71e794

Please sign in to comment.