extern const uint8_t gamma[];
extern const uint8_t sine[];
extern const uint8_t cosine[];
int led = 11; // the PWM pin the LED is attached to
int brightness; // how bright the LED is
int corrected;
int dwell;
void setup()
{
pinMode(led, OUTPUT);
dwell = 5;
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Serial.begin(115200);
}
void loop()
{
switch (1) {
case 0:
for (brightness = 31; brightness < 248; brightness ++)
{
commonfunc();
}
for (brightness = 248; brightness > 31; brightness --)
{
commonfunc();
}
break;
case 1:
sineGammaLed();
break;
default:
;
}
}
void commonfunc ()
{
corrected = pgm_read_byte(&gamma[brightness]);
analogWrite(led, corrected);
delay(dwell);
}
void sineGammaLed ()
{ static int i =0;
static int inc = 1;
static long interval = 100000;
static unsigned long last = 0;
unsigned long now = micros();
if (now - last >= interval) {
last = now;
corrected = pgm_read_byte(&gamma[i]);
analogWrite(led, corrected);
delay(dwell);
// FIXME not quite right -- still hard bounce at PI/2
//interval = pgm_read_byte(&cosine[(i-31)*255L/(255-31)])*20;
corrected = 127*(1+sin(now*2*M_PI/4000000L));
corrected = pgm_read_byte(&gamma[corrected]);
i += inc;
if( i > 255){
i = 255 ;
inc = -1;
}
if( i < 31 ){
i = 31 ;
inc = 1;
Serial.println();
}
analogWrite(led,corrected);
// Serial.print(i);
Serial.print(" c:");
Serial.print(corrected);
// Serial.print(" i:");
// Serial.print(interval);
Serial.print(' ');
}
}
const uint8_t PROGMEM gamma[] = {
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 sine[] = {
0, 2, 3, 5, 6, 8, 9, 11, 13, 14, 16, 17, 19, 20, 22, 24,
25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 42, 44, 45, 47, 48,
50, 51, 53, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 70, 71, 73,
74, 76, 77, 79, 80, 82, 83, 85, 86, 88, 89, 91, 92, 94, 95, 96,
98, 99,101,102,104,105,107,108,109,111,112,114,115,116,118,119,
121,122,123,125,126,127,129,130,132,133,134,136,137,138,140,141,
142,143,145,146,147,149,150,151,152,154,155,156,157,159,160,161,
162,164,165,166,167,168,169,171,172,173,174,175,176,178,179,180,
181,182,183,184,185,186,187,188,190,191,192,193,194,195,196,197,
198,199,200,201,202,203,203,204,205,206,207,208,209,210,211,212,
213,213,214,215,216,217,218,218,219,220,221,222,222,223,224,225,
225,226,227,228,228,229,230,230,231,232,232,233,234,234,235,235,
236,237,237,238,238,239,239,240,241,241,242,242,243,243,243,244,
244,245,245,246,246,247,247,247,248,248,248,249,249,249,250,250,
250,251,251,251,251,252,252,252,252,253,253,253,253,253,254,254,
254,254,254,254,254,255,255,255,255,255,255,255,255,255,255,255 };
const uint8_t PROGMEM cosine[] = {
255,255,255,255,255,255,255,255,255,255,255,254,254,254,254,254,
254,254,253,253,253,253,253,252,252,252,252,251,251,251,251,250,
250,250,249,249,249,248,248,248,247,247,247,246,246,245,245,244,
244,243,243,243,242,242,241,241,240,239,239,238,238,237,237,236,
235,235,234,234,233,232,232,231,230,230,229,228,228,227,226,225,
225,224,223,222,222,221,220,219,218,218,217,216,215,214,213,213,
212,211,210,209,208,207,206,205,204,203,203,202,201,200,199,198,
197,196,195,194,193,192,191,190,188,187,186,185,184,183,182,181,
180,179,178,176,175,174,173,172,171,169,168,167,166,165,164,162,
161,160,159,157,156,155,154,152,151,150,149,147,146,145,143,142,
141,140,138,137,136,134,133,132,130,129,128,126,125,123,122,121,
119,118,116,115,114,112,111,109,108,107,105,104,102,101, 99, 98,
96, 95, 94, 92, 91, 89, 88, 86, 85, 83, 82, 80, 79, 77, 76, 74,
73, 71, 70, 68, 67, 65, 64, 62, 61, 59, 58, 56, 55, 53, 51, 50,
48, 47, 45, 44, 42, 41, 39, 38, 36, 34, 33, 31, 30, 28, 27, 25,
24, 22, 20, 19, 17, 16, 14, 13, 11, 9, 8, 6, 5, 3, 2, 0 };