I have one final element to put together for my prototype sketch.
I have two sketches that work on their own but I will need to merge them
My code is ugly, right now, but functional.
So, what I want to do is have a switch (BTN1) set a pin high, and turn on two LEDs (LED1 and LED2). Simple to do on it's own. I have it done several times in my sketches (I have 20 or so that I have done now).
BUT, what I need to do is, when a second momentary (BTN2) is pressed, I want to toggle between the first pair of LEDs and a second pair of LEDs (LED3 and LED4).
And, of course, if I turn the switch off it will turn off the LEDs.
I have a couple toggle sketches worked up and they work fine. But there's code in the void setup in those sketches that will interfere, or be cancelled, by the original function of the entire project.
I'm not looking for code, as I'm learning that and have probably enough knowledge of it to be dangerous. I'm looking for the logical way of addressing it. If that makes sense.
My gut instinct is to have two different ways of identifying the state of the LEDs. That way I can refer to them in one way in the main code of the sketch and a "special" way of referring to them in the exception part of the code.
Did that make sense?
If it helps, this is the part of the code that toggles the LEDs
buttonState = digitalRead(buttonPin);
if( (millis() - lastDebounceTime) > debounceDelay) {
if ( (buttonState == HIGH) && (ledState01 < 0) ){
digitalWrite(ledPin01,HIGH); //Turns on LED01 if it was off
ledState01 = -ledState01; //Flips the perceived state of LED01
digitalWrite(ledPin02,LOW); //Turns off LED02 if it was on
ledState02 = -ledState02; //Flips the perceived state of LED02
digitalWrite(ledPin03,HIGH); //Turns on LED03 if it was off
ledState03 = -ledState03; //Flips the perceived state of LED03
digitalWrite(ledPin04,LOW); //Turns off LED04 if it was on
ledState04 = -ledState04; //Flips the perceived state of LED04
lastDebounceTime = millis(); //Resets the counter for the debounce
}
else if( (buttonState == HIGH) && (ledState01 > 0) ){
digitalWrite(ledPin01,LOW); //Turns off LED01 if it was on
ledState01 = -ledState01; //Flips the perceived state of LED01
digitalWrite(ledPin02,HIGH); //Turns on LED02 if it was off
ledState02 = -ledState02; //Flips the perceived state of LED02
digitalWrite(ledPin03,LOW); //Turns on LED03 if it was off
ledState03 = -ledState03; //Flips the perceived state of LED03
digitalWrite(ledPin04,HIGH); //Turns off LED04 if it was on
ledState04 = -ledState04; //Flips the perceived state of LED04
lastDebounceTime = millis(); //Resets the counter for the debounce
}