hi im trying to make a pushbutton change the state of my rgb led... so basically, i turn it on, press the button and it goes from red to blue, and then i press it again it goes from blue to red. please tell me what i have done wrong as my code isnt working.
thanks!
any help will be appreciated!
const int buttonPin = 2;
const int ledPin1 = 13;
const int ledpin2 = 11;
int ledState1 = HIGH;
int ledState2 = LOW;
int ledState = HIGH:
int buttonState;
int lastButtonState = LOW;
long lastDebounceTime = 0;
long debounceDelay = 50;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin1, OUTPUT);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
if (buttonState == HIGH) {
if(ledPin1 == HIGH && ledpin2 == LOW)
{
ledState1 = !ledState1;
ledState2 = !ledState2;
}
if(ledpin2 == HIGH && ledPin1 == LOW)
{
ledState1 = !ledState1;
ledState2 = !ledState2;
}
}
}
if ((millis() - lastDebounceTime) > debounceDelay) {
buttonState = reading;
}
digitalWrite(ledPin1, ledState1);
digitalWrite(ledpin2, ledState2);
lastButtonState = reading;
}