forgot to commit everything...
This commit is contained in:
44
user/FadeOnce.h
Executable file
44
user/FadeOnce.h
Executable file
@@ -0,0 +1,44 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user