For starters, thanks for the info.
As for the pot input being more responsive, as soon as I read your response the fact that I should have put an analog read in each for statement became painfully obvious to me. I adjusted the code and it works great. I plan on looking into your second suggestion for this issue later just to expand my knowledge.
When next I get some free time I plan on adding code to monitor the button presses in the fades as suggested, I'll let you know how that turns out.
As far as the structure of my code, listed below is the hopefully not too poorly written sketch. I am slowly adding functionality as I go and troubleshooting as req'd.
/*
*RGB LED LAMP PROJECT
*
*/
volatile int Mode = 0;
int fast = 0;
int redPotPin = 1; // select the input pin for the potentiometer
int greenPotPin = 2;
int bluePotPin = 3;
int redLedPin = 9; // select the pin for the LED
int greenLedPin = 10;
int blueLedPin = 11;
int redVal = 0; // variable to store the value
int greenVal = 0;
int blueVal = 0;
void setup() {
attachInterrupt(0, next, RISING); // Button attached to interrupt 0, digital pin 2,
// to trigger fuction next when button goes from low to high
Serial.begin(9600);
pinMode(redLedPin, OUTPUT); // declare the ledPin as an OUTPUT
pinMode(greenLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
}
void loop(){
// Now do whatever the Mode indicates
if (Mode == 0) {
redVal = analogRead(redPotPin); // read the value from the sensor
analogWrite(redLedPin, redVal/4); // convert from 0-1023 to 0-255 and apply value to LED
greenVal = analogRead(greenPotPin);
analogWrite(greenLedPin, greenVal/4);
blueVal = analogRead(bluePotPin);
analogWrite(blueLedPin, blueVal/4);
}
if (Mode == 1) {
{
analogWrite(greenLedPin, 0);
analogWrite(redLedPin, 0);
analogWrite(blueLedPin, 0);
fast = analogRead(redPotPin)/50;
fast = max(fast, 1); // limits fast to a min. of 1 by selecting
} // The higher of the two values ,fast or 1,
// and asigining it to fast.
for (int redVal=0; redVal<=255; redVal++) {
analogWrite(redLedPin, redVal);
fast = analogRead(redPotPin)/50;
fast = max(fast, 1);
delay(fast);
}
for (int redVal=255; redVal>=0; redVal--) {
analogWrite(redLedPin, redVal);
fast = analogRead(redPotPin)/50;
fast = max(fast, 1);
delay(fast);
}
}
if (Mode == 2) {
for (int greenVal=0; greenVal<=255; greenVal++) {
analogWrite(greenLedPin, greenVal);
delay(10);
}
for (int greenVal=255; greenVal>=0; greenVal--) {
analogWrite(greenLedPin, greenVal);
delay(10);
}
}
if (Mode == 3) {
for (int blueVal=0; blueVal<=255; blueVal++) {
analogWrite(blueLedPin, blueVal);
delay(10);
}
for (int blueVal=255; blueVal>=0; blueVal--) {
analogWrite(blueLedPin, blueVal);
delay(10);
}
}
}
void next()
{
if (Mode == 0) { //
Mode = 1; //
}
else {
if (Mode == 1) { //
Mode = 2; //
}
else {
if (Mode == 2) { //
Mode = 3; //
}
else {
if (Mode == 3) { // above 3 it returnes to 0
Mode = 0; //
}
}
}
}
}
Any further input/suggestions are welcome.
Thanks again.