3 LEDs, Smooth fading

Fun with 3 LEDs,
Connect them to pins 9, 10, 11 and upload the sketch
(Extra points if you arrange them in a triad.)

// fadeupdowngamma03
// three phases
// gamma-corrected, smooth fading
//
extern const uint8_t gamma[];
extern const uint8_t gamma120[];
extern const uint8_t gamma240[];
byte led1 = 9;
byte led2 = 10;
byte led3 = 11;
int brightness;
int corrected;
byte corrected2;
byte corrected3;
void setup() 
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
}
void loop() 
{
  for (brightness = 0; brightness < 510; brightness ++)
  {
    corrected = pgm_read_byte(&gamma[brightness]);
    corrected2 = pgm_read_byte(&gamma120[brightness]);
    corrected3 = pgm_read_byte(&gamma240[brightness]);
    analogWrite(led1, corrected);
    analogWrite(led2, corrected2);
    analogWrite(led3, corrected3);
    delay(4);   //  fade speed
  }
}
//  0 degrees
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,
252,249,247,244,241,239,236,233,231,228,225,223,220,218,215,213, 
210,208,205,203,200,198,196,193,191,189,186,184,182,180,177,175, 
173,171,169,167,164,162,160,158,156,154,152,150,148,146,144,142, 
140,138,137,135,133,131,129,127,126,124,122,120,119,117,115,114, 
112,110,109,107,105,104,102,101,99,98,96,95,93,92,90,89,
87,86,85,83,82,81,79,78,77,75,74,73,72,70,69,68,
67,66,64,63,62,61,60,59,58,57,56,55,54,52,51,50, 
50,49,48,47,46,45,44,43,42,41,40,39,39,38,37,36, 
35,35,34,33,32,32,31,30,29,29,28,27,27,26,25,25, 
24,24,23,22,22,21,21,20,20,19,19,18,18,17,17,16, 
16,15,15,14,14,13,13,13,12,12,11,11,11,10,10,10, 
9, 9, 9, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 5, 5, 
5, 5, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 
2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 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};

const uint8_t PROGMEM gamma120[] = {
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,252,249,247,244,241,
239,236,233,231,228,225,223,220,218,215,213,210,208,205,203,200,
198,196,193,191,189,186,184,182,180,177,175,173,171,169,167,164,
162,160,158,156,154,152,150,148,146,144,142,140,138,137,135,133,
131,129,127,126,124,122,120,119,117,115,114,112,110,109,107,105,
104,102,101,99,98,96,95,93,92,90,89,87,86,85,83,82,
81,79,78,77,75,74,73,72,70,69,68,67,66,64,63,62,
61,60,59,58,57,56,55,54,52,51,50,50,49,48,47,46,
45,44,43,42,41,40,39,39,38,37,36,35,35,34,33,32,
32,31,30,29,29,28,27,27,26,25,25,24,24,23,22,22,
21,21,20,20,19,19,18,18,17,17,16,16,15,15,14,14,
13,13,13,12,12,11,11,11,10,10,10,9,9,9,8,8,
8,7,7,7,7,6,6,6,6,5,5,5,5,4,4,4,
4,4,3,3,3,3,3,3,3,2,2,2,2,2,2,2,
2,1,1,1,1,1,1,1,1,1,1,1,1,1,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,
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};

const uint8_t PROGMEM gamma240[] = {
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,252,249,247,244,241,239,236,233,231,228,225,
223,220,218,215,213,210,208,205,203,200,198,196,193,191,189,186,
184,182,180,177,175,173,171,169,167,164,162,160,158,156,154,152,
150,148,146,144,142,140,138,137,135,133,131,129,127,126,124,122,
120,119,117,115,114,112,110,109,107,105,104,102,101,99,98,96,
95,93,92,90,89,87,86,85,83,82,81,79,78,77,75,74,
73,72,70,69,68,67,66,64,63,62,61,60,59,58,57,56,
55,54,52,51,50,50,49,48,47,46,45,44,43,42,41,40,
39,39,38,37,36,35,35,34,33,32,32,31,30,29,29,28,
27,27,26,25,25,24,24,23,22,22,21,21,20,20,19,19,
18,18,17,17,16,16,15,15,14,14,13,13,13,12,12,11,
11,11,10,10,10,9,9,9,8,8,8,7,7,7,7,6,
6,6,6,5,5,5,5,4,4,4,4,4,3,3,3,3,
3,3,3,2,2,2,2,2,2,2,2,1,1,1,1,1,
1,1,1,1,1,1,1,1,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,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};

fadeupdownwgamma03.ino (5.66 KB)