save potentiometer values in array

Im making a lamp for an instructables contest and have run into a dead end. The lamp has 3 pots controlling rgb values. I want the user to click a button to store the set values. After storing a few values they can click another to fade them together. one of the pots will then control the speed of the fade.

I have successfully gotten the pots to control the rgb values. On other lamps i have been able to fade pre set values together and control the speed with a pot. I cant get the the pot values to store and then fade back.

My idea is that i need to store them in two arrays. ex rgb[3]; being the pot combo, and place[9]; so the user can choose up to 9 combinations of rgb values.

this is my idea of how to save it.

void savecolor()
{
  if (fadechoose = HIGH)
  {
  rpotval = rgb[0];
  gpotval = rgb[1];
  bpotval = rgb[2];

rgb[3] = place[9];

  }
else
{}

}

and this is my idea on how to call the values

void displaycolors()
{


  if(fadeon = HIGH)
  {
crossFade(place[0]);
crossFade(place[1]);
crossFade(place[2]);
}
    else
    {}

i get a compiler error of "invalid conversion from 'int' to 'int*' for the crossFade to usually work it would be written like int red[3] = {255, 0, 0}; crossFade(red);

Thank you for you time

Do you remember, when you read the sticky thread about how to use the forum, that it said that you should post all your code? Well...

  if(fadeon = HIGH)

fadeon will definitely be HIGH, because that statement assigns HIGH to it. You want == not = .

I can give all of the code if you would like. Its a bit messy right now though.
Nick thanks for pointing that out. I keep making simple syntax errors like that.

                       //led pins 
const int red =11;
const int green =9;
const int blue =10;

                       //potentiometer pins
const int rpot =A3;
const int gpot =A4;
const int bpot =A5;

                      //potentiometer values
int rpotval = 0;
int gpotval = 0;
int bpotval = 0;

                        //buttons 
int fadeon =2; 
int fadechoose =3;

                        //packages the values 
int rgb[3];
int place[9];
int column = 0;

int fadeval1;
int fadeval2;
int fadeval3;

                            // saved values
int black[3] = {0, 0, 0};
int redVal= black[0];
int grnVal= black[1];
int bluVal= black[2];
int prevR = redVal;
int prevG = grnVal;
int prevB = bluVal;
  int rval1;
  int gval1;
  int bval1;

void setup()
{
                           //declair pins functions 
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
pinMode(fadechoose, INPUT);
pinMode(fadeon, INPUT);
  
  Serial.begin(9600);
}
  void loop()
{
                                                    // reads potentiometers value and turns it from 1023 to 255 
  rpotval = map(analogRead(rpot), 0, 1024, 0, 255);
  gpotval = map(analogRead(gpot), 0, 1024, 0, 255);
  bpotval = map(analogRead(bpot), 0, 1024, 0, 255);
 /*if (rpotval >= 254)
 {
   rpotval = 255;
 }
 if (gpotval >= 254)
 {
   gpotval = 255;
 }
 if (bpotval >=254)
 {
   bpotval = 255;
 }*/
    // sends values to leds so you can pick full range of colors
analogWrite(red, rpotval);
analogWrite(green, gpotval);
analogWrite(blue, bpotval);
delay(3);
}
      int calculateStep(int prevValue, int endValue)
{
      int step = endValue - prevValue;
      if (step) 
      {
        step = 255/step;
      }
      return step; 
    }
    
    int calculateVal(int step, int val, int i) 
{
if ((step) && i % step == 0)
{
  if (step > 0)
  { 
    val += 1;
  }
  else if (step < 0) 
  {
    val -= 1;
  }
}

if (val > 255)
{
  val = 255;
}
if (val < 0)
{
  val = 0;
}
return val;
}


                                 //stores the color in memory 
void savecolor()
{
  if (fadechoose == HIGH)
  {
  rpotval = rgb[0];
  gpotval = rgb[1];
  bpotval = rgb[2];

rgb[3] = place[9];

  }
else
{}

}



void crossFade(int color[3])
{ 
  int R = color[0];
  int G = color[1];
  int B = color[2];
  
  int stepR = calculateStep(prevR, R);
  int stepG = calculateStep(prevG, G);
  int stepB = calculateStep(prevB, B);
  
  
  for (int i = 0; i <= 255; i++)
  {
    redVal = calculateVal(stepR, redVal, i);
    grnVal = calculateVal(stepG, grnVal, i);
    bluVal = calculateVal(stepB, bluVal, i);
    
    
 analogWrite(red, redVal);
 analogWrite(green, grnVal);
 analogWrite(blue, bluVal);


}
}

                                       // fades  stored values 
void displaycolors()
{


  if(fadeon == HIGH)
  {
crossFade(place[0]);
crossFade(place[1]);
crossFade(place[2]);
}
    else
    {}
    
delay(3);

Serial.println("rval1");
Serial.println (rval1);
Serial.println("gval1");
Serial.println(gval1);
Serial.println("bval1");
Serial.println(bval1);
Serial.println(" red output ");
    Serial.println(rpotval);
    Serial.println("green output ");
    Serial.print(gpotval);
    Serial.println(" blue output ");
    Serial.print(bpotval);

   
    delay(200);
  }
void crossFade(int color[3])
crossFade(place[0]);

You've told the compiler you're going to pass an array to "crossFade", but you're only giving it one element.

  if(fadeon == HIGH)
  {
crossFade(place[0]);
crossFade(place[1]);
crossFade(place[2]);
}
    else
    {}

This is just confusing. Don't do it.

It's like saying, "if it rains, take an umbrella, if not, do nothing". The "do nothing" is implied. It just clutters up your code putting it there.

And, if I may suggest, use the auto-format tool in the IDE. Your indentation is all over the place.

Thanks for the auto format suggestion, its a lot cleaner now. Also Im glad to know that i dont need the else {}. I was not sure so i just put it in there.
AWOL i see what your saying but im stuck here. i want ‘place’ to include 3 elements for each of its one.
im going to attempt to make is visual.

R[0] G[1] B[2]
place [0] { 0 , 255, 34 }
place [1] { 232 , 231, 100 }
and so on…

It looks like you need a two dimensional array. Like place[4][3]

ok mike thanks, thats actually what i was trying in the first place. I talked to my into to c++ teacher about this project and she recommended that but does not know about arduino. I tried it out but got messages about something along the lines of a int not being able to go into a int so i though arduino might not be capable of that and tried other ways. I guess i will keep working on making the double arrays. Im not fully understanding how they work though. how do i assign what column goes where?

The Arduino uses C++ so it can do what you need here with the arrays

Im not fully understanding how they work though. how do i assign what column goes where?

Ask your C/C++ teacher

its spring break right now so i guess i will just have to hit the books. we are going to cover arrays at the end of the semester.

thanks for putting me back on the right path :)

ok... so i know i should probably stop and figure this out on my own. But i looked it up and feel this should work. i get "invalid types 'int[3][int[3]' for array subscript" but rgb is a array of 3 and i have it set up as int place[3][9]; im thinking that if this worked then i would just call to fade column.

void savecolor() { if (fadechoose == HIGH) { rpotval = rgb[0]; gpotval = rgb[1]; bpotval = rgb[2];

column = place[9][rgb];

}

yea... that was very wrong. I will post back here with more questions after i do some good trial and error. or i will post back with the correct code for reference.

This is an example of how you initialise a two dimensional array:-

int multLimit [5][4] = { {6, 9, 12, 15 },  { 5, 10, 15, 20},  { 6, 12, 18, 24 }, { 7, 14, 21, 28 }, { 7, 11, 13, 17 } };

yes, thank you, i was watching youtube videos and reading c++ sites about that last night. But this does not allow the data to be changed by potentiometers. I was thinking of setting all values to 0 like this

int place[9][3]={{0}};

and saving the pot vals like this

void savecolor()
{
  if (fadechoose == HIGH)
  {
    rpotval = rgb[0];
    gpotval = rgb[1];
    bpotval = rgb[2];

 int place[9][3] = {{rpotval, gpotval, bpotval},
 {rpotval, gpotval, bpotval},
 {rpotval, gpotval, bpotval},
 {rpotval, gpotval, bpotval},
 {rpotval, gpotval, bpotval},
 {rpotval, gpotval, bpotval},
 {rpotval, gpotval, bpotval},
 {rpotval, gpotval, bpotval},
 {rpotval, gpotval, bpotval}};

  }

}

then this is how i was thinking of displaying them through fade.

void displaycolors()
{


  if(fadeon == HIGH)
  {
for (int rgbval = 0; rgbval<=3; rgbval++)
{
  for(int i = 0; i <=9; i++)
{
  place[i][rgbval] = crossFade;
}
}
  }

it still needs work but thats what i got to by the end of the night.

my latest error is "invalid conversion from ‘void ()(int)’ to ‘int’

i know i need to better call the saved info in the array but am i actually saving it?

int place[9][3]={{0}};if it is a global or static, it will be initialized to zero unless you explictly initialise it to something else.

so then ={{0}}; is not needed?

but i need to initialize it all to 0 to be able to change the values later right?