forked from bitluni/bitluniHomeAutomation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WaveFunction.h
43 lines (38 loc) · 1.02 KB
/
WaveFunction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
Released under Creative Commons Attribution 4.0
by bitluni 2016
https://creativecommons.org/licenses/by/4.0/
Attribution means you can use it however you like as long you
mention that it's base on my stuff.
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
*/
#include <math.h>
#include "LedFunction.h"
class WaveFunction: public LedFunction
{
public:
long sinTab[256];
uint8_t rgb[3] = {0, 0, 0};
int start;
WaveFunction()
{
for(int i = 0; i < 256; i++)
sinTab[i] = sin(3.1415 / 128 * i) * 0x7fff + 0x8000;
start = millis();
}
virtual bool init(ESP8266WebServer &server)
{
if(!loadRGBValues(server, rgb))
return false;
}
virtual void render()
{
int j = ((millis() - start) / 63) & 255;
int k = ((millis() - start) / 71) & 255;
for(int i = 0; i < state->count; i++)
{
long s = (sinTab[(i*3 + j) & 255] >> 8) * (sinTab[-(i*4 + k) & 255] >> 8);
state->setRgb(i, (rgb[0] * s) >> 16, (rgb[1] * s) >> 16, (rgb[2] * s) >> 16);
}
}
};