45 lines
719 B
C++
Executable File
45 lines
719 B
C++
Executable File
#ifndef FLASHONCE_H
|
|
#define FLASHONCE_H
|
|
|
|
|
|
#include "ESP8266lib/ext/led/WS2812B.h"
|
|
|
|
/** fade between two colors */
|
|
class FadeOnce {
|
|
|
|
Color c1;
|
|
Color c2;
|
|
int fadeOut_ticks = 0;
|
|
int ticksLeft = 0;
|
|
|
|
public:
|
|
|
|
/** ctor */
|
|
FadeOnce() {
|
|
;
|
|
}
|
|
|
|
void setColor(Color c1, Color c2) {
|
|
this->c1 = c1;
|
|
this->c2 = c2;
|
|
}
|
|
|
|
void setFadeDuration(int duration_ticks) {
|
|
this->fadeOut_ticks = duration_ticks;
|
|
this->ticksLeft = duration_ticks;
|
|
}
|
|
|
|
void update() {
|
|
if (ticksLeft > 0) {--ticksLeft;} // fade-out
|
|
}
|
|
|
|
Color getCurrent() const {
|
|
const int percent = (ticksLeft * 100 / fadeOut_ticks);
|
|
return Color::mix(c1, c2, percent);
|
|
}
|
|
|
|
};
|
|
|
|
|
|
#endif // FLASHONCE_H
|