[SOLVED] Need help to Save a lot of Variables not in Sketch

Hey Guys!

i have been working with Arduino for about 1 month now, that means i'm Quite new to this.

I'm making a project with an RGB LED Strip (With DATA Pin).

And now i want to adjust the "Kelvin Value" with a potentiometer.
I have a list with all the RGB values for a white from 1000 to 12000 Kelvin. This List contains 110 Whites with a different Kelvin value, but i don't want to create 110 new Variables in my Sketch. I will map down the Potentiometer value from 1024 to 110, so that i can adjust every Kelvin value.

Now i don't know if i have to create 110 Variables or create something like a "Variable Library".

I would be very thankful if someone could help me!

(Btw. i'm from Switzerland, this means that i speak German, sorry if my grammar is not perfect :slight_smile: )

Thanks in advance!

Regards

Dario Casciato

This is the List of all RGB values for the Kelvin values from 1000K to 12000K:

    1000: (255, 56, 0),
    1100: (255, 71, 0),
    1200: (255, 83, 0),
    1300: (255, 93, 0),
    1400: (255, 101, 0),
    1500: (255, 109, 0),
    1600: (255, 115, 0),
    1700: (255, 121, 0),
    1800: (255, 126, 0),
    1900: (255, 131, 0),
    2000: (255, 138, 18),
    2100: (255, 142, 33),
    2200: (255, 147, 44),
    2300: (255, 152, 54),
    2400: (255, 157, 63),
    2500: (255, 161, 72),
    2600: (255, 165, 79),
    2700: (255, 169, 87),
    2800: (255, 173, 94),
    2900: (255, 177, 101),
    3000: (255, 180, 107),
    3100: (255, 184, 114),
    3200: (255, 187, 120),
    3300: (255, 190, 126),
    3400: (255, 193, 132),
    3500: (255, 196, 137),
    3600: (255, 199, 143),
    3700: (255, 201, 148),
    3800: (255, 204, 153),
    3900: (255, 206, 159),
    4000: (255, 209, 163),
    4100: (255, 211, 168),
    4200: (255, 213, 173),
    4300: (255, 215, 177),
    4400: (255, 217, 182),
    4500: (255, 219, 186),
    4600: (255, 221, 190),
    4700: (255, 223, 194),
    4800: (255, 225, 198),
    4900: (255, 227, 202),
    5000: (255, 228, 206),
    5100: (255, 230, 210),
    5200: (255, 232, 213),
    5300: (255, 233, 217),
    5400: (255, 235, 220),
    5500: (255, 236, 224),
    5600: (255, 238, 227),
    5700: (255, 239, 230),
    5800: (255, 240, 233),
    5900: (255, 242, 236),
    6000: (255, 243, 239),
    6100: (255, 244, 242),
    6200: (255, 245, 245),
    6300: (255, 246, 247),
    6400: (255, 248, 251),
    6500: (255, 249, 253),
    6600: (254, 249, 255),
    6700: (252, 247, 255),
    6800: (249, 246, 255),
    6900: (247, 245, 255),
    7000: (245, 243, 255),
    7100: (243, 242, 255),
    7200: (240, 241, 255),
    7300: (239, 240, 255),
    7400: (237, 239, 255),
    7500: (235, 238, 255),
    7600: (233, 237, 255),
    7700: (231, 236, 255),
    7800: (230, 235, 255),
    7900: (228, 234, 255),
    8000: (227, 233, 255),
    8100: (225, 232, 255),
    8200: (224, 231, 255),
    8300: (222, 230, 255),
    8400: (221, 230, 255),
    8500: (220, 229, 255),
    8600: (218, 229, 255),
    8700: (217, 227, 255),
    8800: (216, 227, 255),
    8900: (215, 226, 255),
    9000: (214, 225, 255),
    9100: (212, 225, 255),
    9200: (211, 224, 255),
    9300: (210, 223, 255),
    9400: (209, 223, 255),
    9500: (208, 222, 255),
    9600: (207, 221, 255),
    9700: (207, 221, 255),
    9800: (206, 220, 255),
    9900: (205, 220, 255),
    10000: (207, 218, 255),
    10100: (207, 218, 255),
    10200: (206, 217, 255),
    10300: (205, 217, 255),
    10400: (204, 216, 255),
    10500: (204, 216, 255),
    10600: (203, 215, 255),
    10700: (202, 215, 255),
    10800: (202, 214, 255),
    10900: (201, 214, 255),
    11000: (200, 213, 255),
    11100: (200, 213, 255),
    11200: (199, 212, 255),
    11300: (198, 212, 255),
    11400: (198, 212, 255),
    11500: (197, 211, 255),
    11600: (197, 211, 255),
    11700: (197, 210, 255),
    11800: (196, 210, 255),
    11900: (195, 210, 255),
    12000: (195, 209, 255)}

You could put that RGB data in an array. If memory is short, take a look at progmem too.

an array structure. you can either index into the array for values or search for the desired kelvin value

#include <stdint.h>
typedef uint8_t byte;

typedef struct  {
    uint16_t    kelvin;
    byte        red;
    byte        green;
    byte        blue;
} KelvinVal_t;

KelvinVal_t kVals [] = {
    {   1000,  255,   56,    0 },
    {   1100,  255,   71,    0 },
    {   1200,  255,   83,    0 },
    {   1300,  255,   93,    0 },
    {   1400,  255,  101,    0 },
    {   1500,  255,  109,    0 },
    {   1600,  255,  115,    0 },
    {   1700,  255,  121,    0 },
    {   1800,  255,  126,    0 },
    {   1900,  255,  131,    0 },
    {   2000,  255,  138,   18 },
    {   2100,  255,  142,   33 },
    {   2200,  255,  147,   44 },
    {   2300,  255,  152,   54 },
    {   2400,  255,  157,   63 },
    {   2500,  255,  161,   72 },
    {   2600,  255,  165,   79 },
    {   2700,  255,  169,   87 },
    {   2800,  255,  173,   94 },
    {   2900,  255,  177,  101 },
    {   3000,  255,  180,  107 },
    {   3100,  255,  184,  114 },
    {   3200,  255,  187,  120 },
    {   3300,  255,  190,  126 },
    {   3400,  255,  193,  132 },
    {   3500,  255,  196,  137 },
    {   3600,  255,  199,  143 },
    {   3700,  255,  201,  148 },
    {   3800,  255,  204,  153 },
    {   3900,  255,  206,  159 },
    {   4000,  255,  209,  163 },
    {   4100,  255,  211,  168 },
    {   4200,  255,  213,  173 },
    {   4300,  255,  215,  177 },
    {   4400,  255,  217,  182 },
    {   4500,  255,  219,  186 },
    {   4600,  255,  221,  190 },
    {   4700,  255,  223,  194 },
    {   4800,  255,  225,  198 },
    {   4900,  255,  227,  202 },
    {   5000,  255,  228,  206 },
    {   5100,  255,  230,  210 },
    {   5200,  255,  232,  213 },
    {   5300,  255,  233,  217 },
    {   5400,  255,  235,  220 },
    {   5500,  255,  236,  224 },
    {   5600,  255,  238,  227 },
    {   5700,  255,  239,  230 },
    {   5800,  255,  240,  233 },
    {   5900,  255,  242,  236 },
    {   6000,  255,  243,  239 },
    {   6100,  255,  244,  242 },
    {   6200,  255,  245,  245 },
    {   6300,  255,  246,  247 },
    {   6400,  255,  248,  251 },
    {   6500,  255,  249,  253 },
    {   6600,  254,  249,  255 },
    {   6700,  252,  247,  255 },
    {   6800,  249,  246,  255 },
    {   6900,  247,  245,  255 },
    {   7000,  245,  243,  255 },
    {   7100,  243,  242,  255 },
    {   7200,  240,  241,  255 },
    {   7300,  239,  240,  255 },
    {   7400,  237,  239,  255 },
    {   7500,  235,  238,  255 },
    {   7600,  233,  237,  255 },
    {   7700,  231,  236,  255 },
    {   7800,  230,  235,  255 },
    {   7900,  228,  234,  255 },
    {   8000,  227,  233,  255 },
    {   8100,  225,  232,  255 },
    {   8200,  224,  231,  255 },
    {   8300,  222,  230,  255 },
    {   8400,  221,  230,  255 },
    {   8500,  220,  229,  255 },
    {   8600,  218,  229,  255 },
    {   8700,  217,  227,  255 },
    {   8800,  216,  227,  255 },
    {   8900,  215,  226,  255 },
    {   9000,  214,  225,  255 },
    {   9100,  212,  225,  255 },
    {   9200,  211,  224,  255 },
    {   9300,  210,  223,  255 },
    {   9400,  209,  223,  255 },
    {   9500,  208,  222,  255 },
    {   9600,  207,  221,  255 },
    {   9700,  207,  221,  255 },
    {   9800,  206,  220,  255 },
    {   9900,  205,  220,  255 },
    {  10000,  207,  218,  255 },
    {  10100,  207,  218,  255 },
    {  10200,  206,  217,  255 },
    {  10300,  205,  217,  255 },
    {  10400,  204,  216,  255 },
    {  10500,  204,  216,  255 },
    {  10600,  203,  215,  255 },
    {  10700,  202,  215,  255 },
    {  10800,  202,  214,  255 },
    {  10900,  201,  214,  255 },
    {  11000,  200,  213,  255 },
    {  11100,  200,  213,  255 },
    {  11200,  199,  212,  255 },
    {  11300,  198,  212,  255 },
    {  11400,  198,  212,  255 },
    {  11500,  197,  211,  255 },
    {  11600,  197,  211,  255 },
    {  11700,  197,  210,  255 },
    {  11800,  196,  210,  255 },
    {  11900,  195,  210,  255 },
    {  12000,  195,  209,  255 },
};

#define KelvinValSize    sizeof(kVals)/sizeof(KelvinVal_t)

// -----------------------------------------------------------------------------
#include <stdio.h>

int
main ()
{
    KelvinVal_t *p = kVals;

    for (int i = 0; i < KelvinValSize; i++, p++)
        printf ("  %6d   %3d %3d %3d\n", p->kelvin, p->red, p->green, p->blue);
}

Another possibility is to put the data into Excel and ask the solver to give you a set of formulae to calculate the three terms from the Kelvin temperature.

Hey guys!

I solved the problem with 3 Arrays.

one Array for Red, One Array for Green, and one Array for blue.

Here's the code for you:

int redArray[] = {255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 252, 249, 247, 245, 243, 240, 239, 237, 235, 233, 231, 230, 228, 227, 225, 224, 222, 221, 220, 218, 217, 216, 215, 214, 212, 211, 210, 209, 208, 207, 207, 206, 205, 207, 207, 206, 205, 204, 204, 203, 202, 202, 201, 200, 200, 199, 198, 198, 197, 97, 97, 196, 196, 195};
int greenArray[] = {56, 71, 83, 93, 101, 109, 115, 121, 126, 131, 138, 142, 147, 152, 157, 161, 165, 169, 173, 177, 180, 184, 187, 190, 193, 196, 199, 201, 204, 206, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 228, 230, 232, 233, 235, 236, 238, 239, 240, 242, 243, 244, 245, 246, 248, 249, 249, 247, 246, 245, 243, 242, 241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 230, 229, 229, 227, 227, 226, 225, 225, 224, 223, 223, 222, 221, 221, 220, 220, 219, 218, 217, 217, 216, 216, 215, 215, 214, 214, 213, 213, 212, 212, 212, 211, 211, 210, 210, 210, 209};
int blueArray[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 33, 44, 54, 63, 72, 79, 87, 94, 101, 107, 114, 120, 126, 132, 137, 143, 148, 153, 159, 163, 168, 173, 177, 182, 186, 190, 194, 198, 202, 206, 210, 213, 217, 220, 224, 227, 230, 233, 236, 239, 242, 245, 247, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255};

int potPin = A0;
int potVal;

void setup() {
  
  Serial.begin(9600);

  strip.begin();
  strip.show();

}

void loop() {

  potVal = map(analogRead(potPin), 0, 1023, 0, 109);

  
  uint32_t change = strip.Color(redArray[potVal], greenArray[potVal], blueArray[potVal]);
  
  for( int i = 0; i<NUM_LIGHTS; i++){
      strip.setPixelColor(i, change);
      strip.show();
  }


  

}