Last active
December 10, 2020 08:48
-
-
Save ansiwen/88aac7ab7cc7e0bf557ec339924557fb to your computer and use it in GitHub Desktop.
1d wave model for arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use if you want to force the software SPI subsystem to be used for some reason (generally, you don't) | |
// #define FASTLED_FORCE_SOFTWARE_SPI | |
// Use if you want to force non-accelerated pin access (hint: you really don't, it breaks lots of things) | |
// #define FASTLED_FORCE_SOFTWARE_SPI | |
// #define FASTLED_FORCE_SOFTWARE_PINS | |
#include <FastLED.h> | |
#include "rgbw.h" | |
// How many leds are in the strip? | |
#define NUM_LEDS 300 | |
#define DATA_PIN 2 | |
#define F_LOW 3 // number of antinodes | |
#define F_HIGH 18 | |
#define OPEN_ENDS 2 // 0, 1 or 2 | |
#define FADE_WIDTH 32 | |
#define DELAY 50 | |
#define BRIGHTNESS 255 | |
#define XMAS 32 | |
#define Serial NoSerial | |
struct NoSerial { | |
template<typename T> void begin(T) {} | |
template<typename T> void print(T) {} | |
template<typename T> void println(T) {} | |
bool operator!() { return false; } | |
} NoSerial; | |
// This is an array of leds. One item for each led in your strip. | |
CRGBW leds[NUM_LEDS]; | |
int8_t u[NUM_LEDS+2]; | |
int8_t v[NUM_LEDS+2]; | |
template<typename T, size_t N> | |
void printArray(T (&a)[N]) { | |
Serial.print("["); | |
for (size_t x = 0; x<N; ++x) { | |
if (x) Serial.print(", "); | |
Serial.print(a[x]); | |
} | |
Serial.print("]\n"); | |
} | |
inline int limit(int amt, int low, int high) { | |
int result = amt<low?low:amt>high?high:amt; | |
if (result != amt) { | |
Serial.print("Constrained: "); | |
Serial.print(amt); | |
Serial.print(" "); | |
Serial.print(low); | |
Serial.print(" "); | |
Serial.println(high); | |
} | |
return result; | |
} | |
// a() is a pseudo array for the initialization signal | |
// it is memory mapped into the leds array | |
const int a_len = NUM_LEDS*2+2; | |
int8_t& a(size_t i) { | |
if (i < NUM_LEDS) { | |
return (int8_t&)(leds[i].r); | |
} | |
if (i < NUM_LEDS*2) { | |
return (int8_t&)(leds[i-NUM_LEDS].g); | |
} | |
return (int8_t&)(leds[i-NUM_LEDS*2].b); | |
} | |
void printArrayA() { | |
Serial.print("["); | |
for (size_t x = 0; x<a_len; ++x) { | |
if (x) Serial.print(", "); | |
Serial.print(a(x)); | |
} | |
Serial.print("]\n"); | |
} | |
// This function sets up the leds and tells the controller about them | |
void setup() { | |
Serial.begin(115200); | |
while(!Serial); | |
randomSeed(analogRead(0)); | |
// sanity check delay - allows reprogramming if accidently blowing power w/leds | |
//delay(2000); | |
FastLED.addLeds<SK6812, DATA_PIN, RGB>((CRGB*)leds, getRGBWsize(NUM_LEDS)); // GRB ordering is typical | |
FastLED.setBrightness(255); | |
memset(leds, 0, NUM_LEDS*4); | |
for (int x = 0; x<NUM_LEDS+2; ++x) { | |
u[x] = 0; | |
v[x] = 0; | |
} | |
// create a random complex spectrum in the desired frequency band | |
for (int f = F_LOW; f<F_HIGH+1; ++f) { | |
u[f] = random(-128,128); // amplitude | |
v[f] = random(-128,128); // phase | |
} | |
// construct the time signal from the spectrum into a() | |
for (int x = 0; x<a_len; ++x) { | |
double p = 0; | |
for (int f = F_LOW; f<F_HIGH+1; ++f) { | |
p += sin(PI*x*(2*f+OPEN_ENDS)/a_len+PI*v[f]/128)*(u[f]+128); | |
} | |
p /= (F_HIGH-F_LOW+1); | |
a(x) = limit(round(p), -128, 127); | |
} | |
for (int x = 0; x<NUM_LEDS+2; ++x) { | |
u[x] = 0; | |
v[x] = 0; | |
} | |
// fade in/out | |
for (int x = 0; x < FADE_WIDTH; ++x) { | |
a(x) = round(a(x) * (1.0-cos(PI*x/FADE_WIDTH))/2); | |
a(a_len-1-x) = round(a(a_len-1-x) * (1.0-cos(PI*x/FADE_WIDTH))/2); | |
} | |
printArrayA(); | |
} | |
// This function runs over and over, and is where you do the magic to light | |
// your leds. | |
void loop() { | |
static int init_idx = 0; | |
static int u_corr = 0; | |
u[0] = OPEN_ENDS==2 ? u[1] : 0; | |
u[NUM_LEDS+1] = OPEN_ENDS>0 ? u[NUM_LEDS] : 0; | |
// feed initialization signal into wave model | |
if (init_idx < a_len) { | |
u[0] = a(init_idx); | |
a(init_idx) = 0; | |
++init_idx; | |
} | |
int8_t last_u = u[0]; | |
int32_t sum = 0; | |
for (int x = 1; x<NUM_LEDS+1; ++x) { | |
int f = (last_u + u[x+1] - 2*u[x]); | |
v[x] = limit(v[x] + f, -128, 127); | |
last_u = u[x]; | |
u[x] = limit(u[x] + v[x] + u_corr, -128, 127); | |
sum += u[x]; | |
if (init_idx==a_len) { // initialization is done? | |
#ifdef XMAS | |
leds[x-1].w = (random8()||(random8()>XMAS))?leds[x-1].w*31/32:scale8_video(64, BRIGHTNESS); | |
leds[x-1].g = scale8(gamma8(u[x]), 32); | |
leds[x-1].r = gamma8(-u[x]); | |
#else | |
leds[x-1].w = scale8_video(gamma8(u[x]), 255); | |
#endif | |
//leds[x-1].b = gamma8(abs(v[x])-128); | |
} | |
} | |
sum /= NUM_LEDS; | |
if (init_idx==a_len) { | |
FastLED.show(); | |
u_corr = OPEN_ENDS == 2 ? -sum : 0; | |
delay(DELAY); | |
} | |
//Serial.println(t2-t); | |
} | |
const uint8_t PROGMEM gamma_2_2_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, | |
3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, | |
6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 11, 11, 11, 12, | |
12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, | |
20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, 29, | |
30, 30, 31, 32, 33, 33, 34, 35, 35, 36, 37, 38, 39, 39, 40, 41, | |
42, 43, 43, 44, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, | |
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, | |
73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 87, 88, 89, 90, | |
91, 93, 94, 95, 97, 98, 99,100,102,103,105,106,107,109,110,111, | |
113,114,116,117,119,120,121,123,124,126,127,129,130,132,133,135, | |
137,138,140,141,143,145,146,148,149,151,153,154,156,158,159,161, | |
163,165,166,168,170,172,173,175,177,179,181,182,184,186,188,190, | |
192,194,196,197,199,201,203,205,207,209,211,213,215,217,219,221, | |
223,225,227,229,231,234,236,238,240,242,244,246,248,251,253,255 | |
}; | |
const uint8_t PROGMEM gamma_2_2_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, | |
4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, | |
7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, | |
13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, | |
21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 29, 29, 30, | |
31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 39, 39, 40, 41, 42, | |
43, 43, 44, 45, 46, 47, 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, | |
57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, | |
73, 74, 75, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 90, 91, | |
92, 93, 95, 96, 97, 98,100,101,102,104,105,106,108,109,111,112, | |
113,115,116,118,119,120,122,123,125,126,128,129,131,132,134,135, | |
137,139,140,142,143,145,147,148,150,151,153,155,156,158,160,162, | |
163,165,167,168,170,172,174,176,177,179,181,183,185,186,188,190, | |
192,194,196,198,200,201,203,205,207,209,211,213,215,217,219,221, | |
223,225,227,229,232,234,236,238,240,242,244,246,248,251,253,255 | |
}; | |
const uint8_t PROGMEM gamma_2_4_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, | |
2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, | |
5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, | |
9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 14, 14, 14, 15, 15, | |
16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, | |
24, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, 32, 32, 33, 34, 35, | |
35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 43, 44, 45, 46, 47, 48, | |
49, 50, 51, 52, 53, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, | |
65, 66, 67, 68, 69, 70, 71, 73, 74, 75, 76, 77, 78, 80, 81, 82, | |
83, 85, 86, 87, 88, 90, 91, 92, 94, 95, 96, 98, 99,100,102,103, | |
105,106,108,109,111,112,114,115,117,118,120,121,123,124,126,127, | |
129,131,132,134,136,137,139,141,142,144,146,148,149,151,153,155, | |
156,158,160,162,164,166,167,169,171,173,175,177,179,181,183,185, | |
187,189,191,193,195,197,199,201,203,205,207,210,212,214,216,218, | |
220,223,225,227,229,232,234,236,239,241,243,246,248,250,253,255 | |
}; | |
const uint8_t PROGMEM gamma_2_4_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, | |
3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, | |
6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, | |
10, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, | |
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, | |
25, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, | |
36, 37, 38, 39, 39, 40, 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, | |
50, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, | |
65, 67, 68, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, 82, 83, | |
84, 85, 87, 88, 89, 90, 92, 93, 94, 96, 97, 98,100,101,102,104, | |
105,107,108,110,111,113,114,116,117,119,120,122,123,125,126,128, | |
130,131,133,134,136,138,139,141,143,144,146,148,150,151,153,155, | |
157,159,160,162,164,166,168,170,172,173,175,177,179,181,183,185, | |
187,189,191,193,195,197,199,201,203,206,208,210,212,214,216,218, | |
221,223,225,227,229,232,234,236,239,241,243,246,248,250,253,255 | |
}; | |
const uint8_t PROGMEM gamma_2_6_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, | |
3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, | |
7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, | |
13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, | |
20, 21, 21, 22, 22, 23, 24, 24, 25, 25, 26, 27, 27, 28, 29, 29, | |
30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, | |
42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, | |
58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 75, | |
76, 77, 78, 80, 81, 82, 84, 85, 86, 88, 89, 90, 92, 93, 94, 96, | |
97, 99,100,102,103,105,106,108,109,111,112,114,115,117,119,120, | |
122,124,125,127,129,130,132,134,136,137,139,141,143,145,146,148, | |
150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180, | |
182,184,186,188,191,193,195,197,199,202,204,206,209,211,213,215, | |
218,220,223,225,227,230,232,235,237,240,242,245,247,250,252,255 | |
}; | |
const uint8_t PROGMEM gamma_2_6_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, | |
2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, | |
4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, | |
8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, | |
13, 14, 14, 15, 15, 16, 16, 17, 17, 17, 18, 18, 19, 19, 20, 20, | |
21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 28, 28, 29, 30, 30, | |
31, 32, 32, 33, 34, 35, 35, 36, 37, 38, 38, 39, 40, 41, 42, 42, | |
43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 52, 53, 54, 55, 56, 57, | |
58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, | |
77, 78, 79, 80, 82, 83, 84, 86, 87, 88, 90, 91, 92, 94, 95, 96, | |
98, 99,101,102,104,105,107,108,110,111,113,114,116,118,119,121, | |
122,124,126,127,129,131,133,134,136,138,140,141,143,145,147,149, | |
151,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180, | |
182,184,187,189,191,193,195,197,200,202,204,206,209,211,213,216, | |
218,220,223,225,227,230,232,235,237,240,242,245,247,250,252,255 | |
}; | |
const uint8_t PROGMEM gamma_2_8_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, | |
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, | |
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, | |
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, | |
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, | |
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, | |
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, | |
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, | |
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, | |
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114, | |
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142, | |
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175, | |
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, | |
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 | |
}; | |
const uint8_t PROGMEM gamma_2_8_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, | |
2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, | |
3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, | |
6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, | |
11, 11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, | |
17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, | |
26, 27, 28, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 36, 37, | |
38, 39, 40, 40, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, | |
52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 69, | |
70, 71, 72, 74, 75, 76, 77, 79, 80, 81, 83, 84, 85, 87, 88, 90, | |
91, 92, 94, 95, 97, 98,100,101,103,104,106,108,109,111,112,114, | |
116,117,119,121,123,124,126,128,130,131,133,135,137,139,141,143, | |
145,147,148,150,152,154,156,159,161,163,165,167,169,171,173,175, | |
178,180,182,184,187,189,191,194,196,198,201,203,205,208,210,213, | |
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 | |
}; | |
const uint8_t PROGMEM gamma_3_0_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, | |
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, | |
4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 8, | |
8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, | |
14, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, | |
22, 22, 23, 23, 24, 25, 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, | |
32, 33, 34, 35, 35, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, | |
46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, | |
63, 64, 65, 67, 68, 69, 70, 72, 73, 74, 76, 77, 78, 80, 81, 82, | |
84, 85, 87, 88, 90, 91, 93, 94, 96, 97, 99,101,102,104,105,107, | |
109,111,112,114,116,118,119,121,123,125,127,129,131,132,134,136, | |
138,140,142,144,147,149,151,153,155,157,159,162,164,166,168,171, | |
173,175,178,180,182,185,187,190,192,195,197,200,202,205,207,210, | |
213,215,218,221,223,226,229,232,235,237,240,243,246,249,252,255 | |
}; | |
const uint8_t PROGMEM gamma_3_0_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, | |
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, | |
5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, | |
9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, | |
15, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, | |
23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 30, 30, 31, 32, 32, | |
33, 34, 35, 35, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 46, | |
47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 63, | |
64, 65, 66, 67, 69, 70, 71, 72, 74, 75, 76, 78, 79, 80, 82, 83, | |
85, 86, 87, 89, 90, 92, 93, 95, 96, 98,100,101,103,104,106,108, | |
109,111,113,115,116,118,120,122,124,125,127,129,131,133,135,137, | |
139,141,143,145,147,149,151,153,155,158,160,162,164,166,169,171, | |
173,175,178,180,183,185,187,190,192,195,197,200,202,205,208,210, | |
213,215,218,221,224,226,229,232,235,237,240,243,246,249,252,255 | |
}; | |
const uint8_t PROGMEM gamma_3_2_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, | |
3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, | |
6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, | |
11, 12, 12, 12, 13, 13, 14, 14, 14, 15, 15, 16, 16, 17, 17, 18, | |
18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 27, | |
28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 37, 37, 38, 39, 40, | |
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, | |
57, 59, 60, 61, 62, 63, 65, 66, 67, 68, 70, 71, 72, 74, 75, 76, | |
78, 79, 81, 82, 84, 85, 87, 88, 90, 91, 93, 95, 96, 98, 99,101, | |
103,105,106,108,110,112,113,115,117,119,121,123,125,127,129,131, | |
133,135,137,139,141,143,146,148,150,152,154,157,159,161,164,166, | |
168,171,173,176,178,181,183,186,188,191,194,196,199,202,204,207, | |
210,213,216,219,221,224,227,230,233,236,239,242,246,249,252,255 | |
}; | |
const uint8_t PROGMEM gamma_3_2_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, | |
4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, | |
7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, | |
12, 13, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, 18, 18, 19, | |
19, 20, 20, 21, 21, 22, 23, 23, 24, 24, 25, 26, 26, 27, 28, 28, | |
29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, | |
42, 43, 44, 45, 46, 47, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, | |
58, 59, 60, 62, 63, 64, 65, 67, 68, 69, 70, 72, 73, 74, 76, 77, | |
79, 80, 81, 83, 84, 86, 87, 89, 90, 92, 94, 95, 97, 98,100,102, | |
103,105,107,109,110,112,114,116,118,120,122,123,125,127,129,131, | |
133,135,137,140,142,144,146,148,150,153,155,157,159,162,164,166, | |
169,171,174,176,179,181,184,186,189,191,194,197,199,202,205,207, | |
210,213,216,219,222,224,227,230,233,236,239,242,246,249,252,255 | |
}; | |
const uint8_t PROGMEM gamma_3_4_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, | |
2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, | |
5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, | |
9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 14, 14, 15, 15, | |
16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 23, 23, 24, | |
24, 25, 26, 26, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 36, | |
37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, | |
52, 53, 55, 56, 57, 58, 59, 60, 62, 63, 64, 66, 67, 68, 70, 71, | |
72, 74, 75, 77, 78, 80, 81, 83, 84, 86, 87, 89, 90, 92, 94, 95, | |
97, 99,101,102,104,106,108,110,112,114,115,117,119,121,123,125, | |
128,130,132,134,136,138,141,143,145,147,150,152,154,157,159,162, | |
164,167,169,172,174,177,180,182,185,188,190,193,196,199,202,205, | |
208,210,213,216,219,223,226,229,232,235,238,242,245,248,252,255 | |
}; | |
const uint8_t PROGMEM gamma_3_4_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, | |
2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, | |
3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, | |
6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, | |
10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, | |
16, 17, 17, 18, 18, 19, 19, 20, 21, 21, 22, 22, 23, 23, 24, 25, | |
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 36, 37, | |
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, | |
53, 54, 55, 56, 58, 59, 60, 61, 62, 64, 65, 66, 68, 69, 70, 72, | |
73, 74, 76, 77, 79, 80, 82, 83, 85, 86, 88, 89, 91, 93, 94, 96, | |
98,100,101,103,105,107,108,110,112,114,116,118,120,122,124,126, | |
128,130,132,134,137,139,141,143,145,148,150,152,155,157,160,162, | |
164,167,169,172,175,177,180,183,185,188,191,193,196,199,202,205, | |
208,211,214,217,220,223,226,229,232,235,238,242,245,248,252,255 | |
}; | |
const uint8_t PROGMEM gamma_3_6_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | |
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, | |
4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, | |
8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, | |
13, 14, 14, 15, 15, 15, 16, 16, 17, 17, 18, 18, 19, 20, 20, 21, | |
21, 22, 23, 23, 24, 24, 25, 26, 27, 27, 28, 29, 29, 30, 31, 32, | |
33, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 42, 43, 44, 46, 47, | |
48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 61, 62, 63, 64, 66, | |
67, 69, 70, 71, 73, 74, 76, 77, 79, 80, 82, 83, 85, 87, 88, 90, | |
92, 94, 95, 97, 99,101,103,104,106,108,110,112,114,116,118,120, | |
122,125,127,129,131,133,136,138,140,143,145,147,150,152,155,157, | |
160,162,165,168,170,173,176,179,181,184,187,190,193,196,199,202, | |
205,208,211,214,218,221,224,227,231,234,237,241,244,248,251,255 | |
}; | |
const uint8_t PROGMEM gamma_3_6_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | |
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, | |
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 5, 5, | |
5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, | |
9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, | |
14, 15, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 21, 21, 22, | |
22, 23, 23, 24, 25, 25, 26, 27, 27, 28, 29, 30, 30, 31, 32, 33, | |
33, 34, 35, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 46, 47, | |
48, 50, 51, 52, 53, 54, 55, 56, 58, 59, 60, 61, 63, 64, 65, 66, | |
68, 69, 71, 72, 73, 75, 76, 78, 79, 81, 83, 84, 86, 87, 89, 91, | |
92, 94, 96, 98, 99,101,103,105,107,109,111,113,115,117,119,121, | |
123,125,127,129,132,134,136,138,141,143,145,148,150,153,155,158, | |
160,163,165,168,171,173,176,179,182,185,187,190,193,196,199,202, | |
205,208,211,215,218,221,224,227,231,234,238,241,244,248,251,255 | |
}; | |
const uint8_t PROGMEM gamma_3_8_0to255_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, | |
3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, | |
6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, | |
11, 12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 18, 18, | |
19, 19, 20, 20, 21, 21, 22, 23, 23, 24, 25, 25, 26, 27, 28, 28, | |
29, 30, 31, 31, 32, 33, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, | |
43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 60, 61, | |
62, 64, 65, 66, 68, 69, 71, 72, 74, 75, 77, 78, 80, 82, 83, 85, | |
87, 88, 90, 92, 94, 96, 98, 99,101,103,105,107,109,111,113,115, | |
118,120,122,124,126,129,131,133,136,138,141,143,146,148,151,153, | |
156,158,161,164,167,169,172,175,178,181,184,187,190,193,196,199, | |
203,206,209,212,216,219,222,226,229,233,237,240,244,247,251,255 | |
}; | |
const uint8_t PROGMEM gamma_3_8_1to255_table[] = { | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | |
1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, | |
4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, | |
7, 7, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, | |
12, 13, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, 17, 18, 18, 19, | |
20, 20, 21, 21, 22, 22, 23, 24, 24, 25, 26, 26, 27, 28, 28, 29, | |
30, 31, 32, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, | |
44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 55, 57, 58, 59, 60, 62, | |
63, 64, 66, 67, 69, 70, 72, 73, 75, 76, 78, 79, 81, 82, 84, 86, | |
87, 89, 91, 93, 94, 96, 98,100,102,104,106,108,110,112,114,116, | |
118,120,122,125,127,129,131,134,136,139,141,143,146,148,151,154, | |
156,159,162,164,167,170,173,175,178,181,184,187,190,193,196,200, | |
203,206,209,212,216,219,223,226,230,233,237,240,244,248,251,255 | |
}; | |
const uint8_t PROGMEM gamma_table[] = { | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, | |
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, | |
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, | |
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, | |
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, | |
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25, | |
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36, | |
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50, | |
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68, | |
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, | |
90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114, | |
115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142, | |
144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175, | |
177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213, | |
215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 | |
}; | |
inline uint8_t gamma8(int8_t x) { | |
return scale8_video( | |
pgm_read_byte(&gamma_3_0_1to255_table[128+x]), | |
BRIGHTNESS | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Helper file to support RGBW pixels with the FastLED library */ | |
#include <FastLED.h> | |
struct CRGBW { | |
union { | |
struct { | |
union { | |
uint8_t g; | |
uint8_t green; | |
}; | |
union { | |
uint8_t r; | |
uint8_t red; | |
}; | |
union { | |
uint8_t b; | |
uint8_t blue; | |
}; | |
union { | |
uint8_t w; | |
uint8_t white; | |
}; | |
}; | |
uint8_t _raw[4]; | |
}; | |
CRGBW(){} | |
CRGBW(uint8_t rd, uint8_t grn, uint8_t blu, uint8_t wht){ | |
r = rd; | |
g = grn; | |
b = blu; | |
w = wht; | |
} | |
inline void operator = (const CRGB c) __attribute__((always_inline)){ | |
this->r = c.r; | |
this->g = c.g; | |
this->b = c.b; | |
this->white = 0; | |
} | |
}; | |
inline uint16_t getRGBWsize(uint16_t nleds){ | |
uint16_t nbytes = nleds * 4; | |
if(nbytes % 3 > 0) return nbytes / 3 + 1; | |
else return nbytes / 3; | |
} | |
template<int SIZE> | |
class CRGBWArray : public CPixelView<CRGBW> { | |
CRGBW rawleds[SIZE]; | |
public: | |
CRGBWArray() : CPixelView<CRGBW>(rawleds, SIZE) {} | |
using CPixelView::operator=; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment