I am trying to setup three buttons to control the state of an RGB LED strip. So far I have figured out how to control the LEDs, but the buttons are giving me an issue. I have the buttons connected to digital pins 10-12 like the Arduino tutorial (http://arduino.cc/en/tutorial/button) shows. I want to be able to press the red button, for example, and have the red LEDs on, pressing blue button would shutoff red and switch on blue. I am lost and have no idea what to do now :P. Any help is GREATLY appreciated!
//Define colors:
#define REDPIN 5
#define GRNPIN 3
#define BLUPIN 6
//Define buttons:
const int REDBTN = 12;
const int BLKBTN = 11;
const int BLUBTN = 10;
//Changing button #:
int buttonState = 0;
int redState = LOW;
int blackState = LOW;
int blueState = LOW;
void setup()
{
//Setup Outputs:
pinMode(REDPIN, OUTPUT);
pinMode(GRNPIN, OUTPUT);
pinMode(BLUPIN, OUTPUT);
//Setup Inputs:
pinMode(REDBTN, INPUT);
pinMode(BLKBTN, INPUT);
pinMode(BLUBTN, INPUT);
analogWrite(REDPIN, 0);
analogWrite(GRNPIN, 0);
analogWrite(BLUPIN, 0);
}
void loop()
{
//Read digital buttons:
int redState = digitalRead(REDBTN);
int blackState = digitalRead(BLKBTN);
int blueState = digitalRead(BLUBTN);
//Read color and change state:
if (redState == HIGH)
{
int buttonState = 1;
}
else if (blackState == HIGH)
{
int buttonState = 0;
}
else if (blueState == HIGH)
{
int buttonState = 2;
}
//Change the color:
if(buttonState == 0)
{
analogWrite(REDPIN, 0);
analogWrite(GRNPIN, 0);
analogWrite(BLUPIN, 0);
}
else if(buttonState == 1)
{
analogWrite(REDPIN, 255);
analogWrite(GRNPIN, 0);
analogWrite(BLUPIN, 0);
}
else if(buttonState == 2)
{
analogWrite(REDPIN, 0);
analogWrite(GRNPIN, 0);
analogWrite(BLUPIN, 255);
}
}