2 Change brightness of LED linearly to Human eye
3 32 step brightness using 8 bit PWM of Arduino
4 brightness step 24 should be twice bright than step 12 to your eye.
6 https://ledshield.wordpress.com/2012/11/13/led-brightness-to-your-eye-gamma-correction-no/
10 #include <avr/pgmspace.h>
11 #define CIELPWM(a) (pgm_read_byte_near(CIEL8 + a)) // CIE Lightness lookup table function
14 5 bit CIE Lightness to 8 bit PWM conversion
15 https://ledshield.wordpress.com/2012/11/13/led-brightness-to-your-eye-gamma-correction-no/
16 L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856
17 L* = 903.3(Y/Yn), Y/Yn <= 0.008856
20 const uint8_t CIEL8[] PROGMEM = {
21 0, 1, 2, 3, 4, 5, 7, 9, 12,
22 15, 18, 22, 27, 32, 38, 44, 51, 58,
23 67, 76, 86, 96, 108, 120, 134, 148, 163,
24 180, 197, 216, 235, 255
27 int brightness = 0; // initial brightness of LED
29 int led1Pin = 9; // pause between each interval (32)
31 unsigned long startTime = 0; // timing variables
32 const long interval = 12;
36 pinMode(led1Pin, OUTPUT); // declare pin 9 to be an output:
40 unsigned long currentTime = millis();
41 if (currentTime - startTime >= interval)
43 startTime += interval; // increment timing sequence
44 analogWrite(led1Pin, CIELPWM(brightness)); // set the brightness of pin 9:, 0-31, 5 bit steps of brightness
45 brightness += fadeAmount; // change the brightness for next time through the loop:
46 if (brightness == 0 || brightness == 31) // reverse the direction of the fading at the ends of the fade:
48 fadeAmount = -fadeAmount ;