Adding a poteniometer - help please

I am pretty good with hardware but hopeless at programming.

I have built a 4 x tri-color LED changer that will reside inside a display cabinet containing crystal glass in my home. I want the colors to change really slowly. I have made it work by changing the value of the delay statement in the sketch below. What I would like to do is to add a potentiometer connected to the analog0 input. I have done this and it works on a simple test program.

I cannot make this work with the code fragment below. Can some one please give me very specific instructions as to how I may vary the delay(150) statement with a potentiometer please.

Thanks in advance.

// RGB LED - Automatic Color Cycling
//
// Matthew L Beckler 
// matthew at mbeckler dot org

int redPin = 11;
int bluePin = 10;
int greenPin = 9;

int redIn = 0;
int greenIn = 1;
int blueIn = 2;

int redVal;
int greenVal;
int blueVal;

void setup()
{
  redVal = 255;
  greenVal = 255;
  blueVal = 255;
  update();
}

// This function updates the LED outputs.
void update()
{
  analogWrite(redPin, redVal);
  analogWrite(greenPin, greenVal);
  analogWrite(bluePin, blueVal);
}

// This function updates one of the color variables
// either getting brighter or getting dimmer.
// It also updates the outputs and delays for 10 milliseconds.
void color_morph(int* value, int get_brighter)
{
  for (int i = 0; i < 255; i++)
  {
    if (get_brighter)
      (*value)--; 
    else
      (*value)++;
      
    update();
    delay([color=blue]150[/color]); // was 10.  Hold current state for n milliseconds
  }
}

void loop()
{
  // start out at black (all off)
  color_morph(&redVal,   1); // transition to red
  color_morph(&greenVal, 1); // transition to yellow
  color_morph(&redVal,   0); // transition to green
  color_morph(&blueVal,  1); // transition to aqua
  color_morph(&redVal,   0); // transition to white changed value from 1
  color_morph(&greenVal, 0); // transition to violet
  color_morph(&redVal,   0); // transition to blue
  color_morph(&blueVal,  0); // transition to black (all off)
}

delay (map (analogRead (0), 0, 1023, 0, 150));

Really? It was that simple?. Thanks, AWOL.

If you want the breakdown, start at the inner-most level: "analogRead" returns a value 0...1023. This value is passed to "map", which takes the interval 0..1023 (pretty much a fixed interval) and maps it to the interval 0..150 (you can change this if you like). "map"'s returned value is passed into "delay".

It is working perfectly. Thanks again.

Once I saw your code fragment I more or less understood what it was doing but I had never seen the map statement so I went and looked it up.

Now I know how this is done, I can use it again and again on other projects.

I move forward somewhat.

Thanks again, AWOL.