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)
}