My code, as I understand it (I've came back from about a year and a half of not coding) should toggle the RGB LED from red to green, but it stays stuck on green. The code compiles just fine.
My code: (I've modified some of it from the reference tutorials.)
int buttonState = HIGH;
int previous = LOW;
int bluePin = 11;
int greenPin = 10;
int redPin = 9;
int buttonPin = 7;
int buttonPressed = digitalRead(buttonPin);
long time = millis();
long debounce = 200;
void setup()
{
pinMode(buttonPin,INPUT);
pinMode(bluePin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(redPin,OUTPUT);
}
void loop()
{
if (buttonPressed == HIGH && previous == LOW) {
if (buttonState == HIGH)
buttonState = LOW;
else
buttonState = HIGH;
time = millis();
}
previous = buttonPressed;
if (buttonState == HIGH) {
setColor(0,255,0);
}
if (buttonState == LOW) {
setColor(255,0,0);
}
delay(10);
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}