|
|
@ -7,21 +7,58 @@ |
|
|
|
using namespace std; |
|
|
|
|
|
|
|
Led::Led(void) { |
|
|
|
index = 0; |
|
|
|
duration = 0; |
|
|
|
} |
|
|
|
|
|
|
|
void Led::loop_rainbow(void) { |
|
|
|
fill_rainbow(leds, NUM_LEDS, index, 7); |
|
|
|
} |
|
|
|
|
|
|
|
void Led::loop_confetti(void) |
|
|
|
{ |
|
|
|
// random colored speckles that blink in and fade smoothly
|
|
|
|
fadeToBlackBy( leds, NUM_LEDS, 10); |
|
|
|
int pos = random16(NUM_LEDS); |
|
|
|
leds[pos] += CHSV( index + random8(64), 200, 255); |
|
|
|
|
|
|
|
leds[0] = CRGB::White; |
|
|
|
leds[1] = CRGB::White; |
|
|
|
leds[NUM_LEDS-1] = CRGB::White; |
|
|
|
leds[NUM_LEDS-2] = CRGB::White; |
|
|
|
leds[NUM_LEDS-3] = CRGB::White; |
|
|
|
} |
|
|
|
|
|
|
|
void Led::loop_dispense(void) { |
|
|
|
// top: led 9 and 10
|
|
|
|
|
|
|
|
// a colored dot sweeping back and forth, with fading trails
|
|
|
|
fadeToBlackBy( leds, NUM_LEDS, 20); |
|
|
|
int pos = beatsin16( 13, 0, NUM_LEDS-1 ); |
|
|
|
leds[pos] += CHSV( index, 255, 192); |
|
|
|
} |
|
|
|
|
|
|
|
void Led::loop_steady(void) { |
|
|
|
fill_solid(leds, NUM_LEDS, CRGB::Orange); |
|
|
|
} |
|
|
|
|
|
|
|
void Led::changeAnimation(uint8_t num, uint16_t duration) { |
|
|
|
if (duration == 0) this->duration = UINT16_MAX; |
|
|
|
else this->duration = duration; |
|
|
|
if (num == 0) refresh = &Led::loop_steady; |
|
|
|
else if (num == 1) refresh = &Led::loop_dispense; |
|
|
|
else if (num == 2) refresh = &Led::loop_confetti; |
|
|
|
else if (num == 3) refresh = &Led::loop_rainbow; |
|
|
|
} |
|
|
|
|
|
|
|
void Led::setup(void) { |
|
|
|
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); |
|
|
|
leds[0] = CRGB::Red; |
|
|
|
leds[1] = CRGB::Green; |
|
|
|
leds[2] = CRGB::Blue; |
|
|
|
leds[NUM_LEDS-6] = CRGB::White; |
|
|
|
leds[NUM_LEDS-5] = CRGB::White; |
|
|
|
leds[NUM_LEDS-4] = CRGB::White; |
|
|
|
leds[NUM_LEDS-3] = CRGB::White; |
|
|
|
leds[NUM_LEDS-2] = CRGB::White; |
|
|
|
leds[NUM_LEDS-1] = CRGB::White; |
|
|
|
FastLED.setBrightness(96); |
|
|
|
FastLED.setCorrection(TypicalLEDStrip); |
|
|
|
fill_solid(leds, NUM_LEDS, CRGB::White); |
|
|
|
FastLED.show(); |
|
|
|
|
|
|
|
refresh = &Led::loop_steady; |
|
|
|
xTaskCreate( |
|
|
|
&cTaskWrapper, /* Task function. */ |
|
|
|
"ledAnimationTask", /* String with name of task. */ |
|
|
@ -33,7 +70,19 @@ void Led::setup(void) { |
|
|
|
|
|
|
|
void Led::animationTask(void* parameters) { |
|
|
|
while(true) { |
|
|
|
|
|
|
|
if (refresh != nullptr) { |
|
|
|
(*this.*refresh)(); |
|
|
|
FastLED.show(); |
|
|
|
// EVERY_N_MILLISECONDS ( 20) { index++; }
|
|
|
|
index++; |
|
|
|
if (duration == 0) { |
|
|
|
refresh = &Led::loop_steady; |
|
|
|
} else if (duration == UINT16_MAX) { |
|
|
|
} else { |
|
|
|
duration--; |
|
|
|
} |
|
|
|
EVERY_N_SECONDS(300) { changeAnimation(3, 200); } |
|
|
|
} |
|
|
|
vTaskDelay(50 / portTICK_PERIOD_MS); |
|
|
|
} |
|
|
|
Serial.println("LED animation end!"); |
|
|
|