Lookup Table for Led dimming

Hi All,
I’m really struggling with creating and using a lookup table.
I’ve tried using this example

/*
 Change brightness of LED linearly to Human eye
 32 step brightness using 8 bit PWM of Arduino
 brightness step 24 should be twice bright than step 12 to your eye.
*/


 #include <avr/pgmspace.h>
 #define CIELPWM(a) (pgm_read_byte_near(CIEL8 + a)) // CIE Lightness loopup table function

/*
5 bit CIE Lightness to 8 bit PWM conversion
L* = 116(Y/Yn)^1/3 - 16 , Y/Yn > 0.008856
L* = 903.3(Y/Yn), Y/Yn <= 0.008856
*/

prog_uint8_t CIEL8[] PROGMEM = {
0,    1,    2,    3,    4,    5,    7,    9,    12,
15,    18,    22,    27,    32,    38,    44,    51,    58,
67,    76,    86,    96,    108,    120,    134,    148,    163,
180,    197,    216,    235,    255
};

int brightness = 0;    // initial brightness of LED
int fadeAmount = 1;

void setup()  {
// declare pin 9 to be an output:
pinMode(9, OUTPUT);
}

void loop()  {
// set the brightness of pin 9:, 0-31, 5 bit steps of brightness
analogWrite(9, CIELPWM(brightness));
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade: 
if (brightness == 0 || brightness == 31) {
fadeAmount = -fadeAmount ;
}
 // wait for 500 milliseconds to see the bightness change 
delay(500);
}

but it wont even compile (ide 1.6.7 win 10) so any help would be much appreciated

Is there a maximum size for these tables? I’m looking at using 84 values (10 bit pwm) and can a single table be used as reference by multiple functions?

When you say “it wont even compile”, you need to copy and paste the error message.

The maximum size is limited by the amount of memory on your unspecified Arduino. Sure you can share the table. Just make sure the table is declared static, or define the table in a global scope (not in setup() or loop() or any other function). Also, make the name unique (not required but avoids other C++ rules).

Try here

Original Thread the code came from http://forum.arduino.cc/index.php?topic=147818.0

and the error,

Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Log_Dimming:17: error: 'prog_uint8_t' does not name a type

prog_uint8_t CIEL8 PROGMEM = {

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,

from sketch\Log_Dimming.ino.cpp:1:

C:\Users******\Documents\Arduino\Log_Dimming\Log_Dimming.ino: In function 'void loop()':

Log_Dimming:9: error: 'CIEL8' was not declared in this scope

#define CIELPWM(a) (pgm_read_byte_near(CIEL8 + a)) // CIE Lightness loopup table function

^

C:\Users******\Documents\Arduino\Log_Dimming\Log_Dimming.ino:34:16: note: in expansion of macro 'CIELPWM'

analogWrite(9, CIELPWM(brightness));

^

exit status 1
'prog_uint8_t' does not name a type

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

See reply #2