Quick update: I now have a working code. Thanks for all the help everyone. The only problem is that if one of the buttons is held down, the colors will cycle automatically. I have added a delay that somewhat counteracts this, however this project is being designed for a handicapped woman, and i would like to remove any and all possible user error from the equation. Basically, is there a way to limit the program so that no matter how long a button is held down for, it will only step once?
Here is my current code:
const int redledPin = 11;
const int greenledPin = 10;
const int blueledPin = 9;
const int buttonPin1 = 2;
const int buttonPin2 = 3;
int color=1;
void setup ()
{
pinMode (redledPin, OUTPUT);
pinMode (greenledPin, OUTPUT);
pinMode (blueledPin, OUTPUT);
pinMode (buttonPin1, INPUT);
pinMode (buttonPin2, INPUT);
}
void loop ()
{
if (digitalRead(buttonPin1)== LOW)
{
color++; //increment color
if (color >7) color = 1;
delay(750);
}
if (digitalRead(buttonPin2)== LOW)
{
color--; //decrement color
if(color<1) color = 7;
delay(750);
}
switch (color){
case 1: //white
analogWrite(redledPin, 250);
analogWrite(blueledPin, 250);
analogWrite(greenledPin, 250);
break;
case 2: //red
analogWrite(redledPin, 250);
analogWrite(blueledPin, 0);
analogWrite(greenledPin, 0);
break;
case 3: //blue
analogWrite(redledPin, 0);
analogWrite(blueledPin, 250);
analogWrite(greenledPin, 0);
break;
case 4: //green
analogWrite(redledPin, 0);
analogWrite(blueledPin, 0);
analogWrite(greenledPin, 250);
break;
case 5: //aqua
analogWrite(redledPin, 0);
analogWrite(blueledPin, 250);
analogWrite(greenledPin, 250);
break;
case 6: //yellow
analogWrite(redledPin, 250);
analogWrite(blueledPin, 0);
analogWrite(greenledPin, 250);
break;
case 7: //purple
analogWrite(redledPin, 250);
analogWrite(blueledPin, 250);
analogWrite(greenledPin, 0);
break;
}
}