forgot to commit everything...

This commit is contained in:
2018-02-03 16:55:37 +01:00
parent 20d46af1fb
commit 3da4722748
15 changed files with 991 additions and 0 deletions

68
user/Fader.h Executable file
View File

@@ -0,0 +1,68 @@
#ifndef FADER_H
#define FADER_H
#include "ESP8266lib/ext/led/WS2812B.h"
/** fade between two colors */
class FadeBetween {
Color c1;
Color c2;
int pos;
int speed;
int dir;
public:
/** ctor */
FadeBetween() {
restart();
}
void setColor1(Color c1) {
this->c1 = c1;
}
void setColor2(Color c2) {
this->c2 = c2;
}
void restart() {
pos = 0;
speed = 128;
dir = 0;
}
void update() {
if (dir == 0) {
++pos;
if (pos == speed) {dir = 1;}
} else {
--pos;
if (pos == 0) {dir = 0;}
}
}
Color getCurrent() const {
const int fac0 = pos;
const int fac1 = speed - fac0;
Color c;
c.r = clamp( (c1.r * fac0 + c2.r * fac1) / speed );
c.g = clamp( (c1.g * fac0 + c2.g * fac1) / speed );
c.b = clamp( (c1.b * fac0 + c2.b * fac1) / speed );
return c;
}
private:
static inline uint8_t clamp(int val) {
if (val > 255) {return 255;}
if (val < 0) {return 0;}
return val;
}
};
#endif // FADER_H