What's a good logic to write this?

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
}

Did that make sense?

Not really. An LED is either on or off and a convenient way to hold this value is in a variable. Why would you want two variables holding the same information ? Both will need to match at all times in the program so why the need for two ?

Incidentally, in your code fragment you change the state of an LED then change the LED state variable to match. It would be better to change the LED state variable then use that value to change/set the state of the LED. That way everything stays in step. I would also use HIGH and LOW as LED state values. You can flip between the two usingledState = !ledState;

ledState01, 02, 03, 04 ? Sounds like a job for an array to me.

Thanks for the heads up on the !LEDstate thing. I think that might remedy a need in one of my preliminary sketches that had to have the state set to LOW in the setup in order to work.

Arrays will come later. Let me get through this set of learning tasks first.

As for the states canceling each other out, or conflicting, that's where I've been stumped. But the two functions of the sketch don't intermix, per se. The main one just interferes a little with the one I posted.

Using boolean variables for all the buttons and leds is a start.

Next thing is to split the functionality. For examples with functions.
Make a part that debounces the switch.
Make a part that turns on/off the leds according to the led-variables.
Make a part for the logic that sets the led-variables true/false according to the switches.

You could scan the buttons in the loop(), for example 50 or 100 times a second.
And run the 'logic' part only when a button is pressed or released. You have to detect a change in the button. This is done with the current button (after debounce) compared with the previous button state (a variable).

Next step will perhaps be a timeout or blinking leds. That can be done by adding millis() timing for the leds and buttons.

The way I see it you have two sets of two states:

  1. LEDs on / LEDs off
  2. LED Set A selected / LED Set B selected

The first state pair is basically the value of your first button. So the output to the LEDs can basically be whatever the input is. The second state pair is the slightly more tricky, in that you are toggling a state with the same transition.

  1. If the button transitions from LOW to HIGH (i.e., is actively being pressed) then:
    2a. If the led pair selected is A then set it to B.
    2b Else, set the LED pair to A.
  2. Update the status of the LEDs:
    3a. If pair A, turn off pair B and set pair A to the input value.
    3b. Else set pair A off and set pair B to the input value.

Simple enough really - it helps to write what you want as a simple list like that - makes it pretty obvious how to implement it then.

Well, I did write the steps out but now I'm having problems getting the code to work.
Probably just a matter of time.

My main problem, today, was the verbiage. I wrote the codes in two different sketches and had led01_state in one and LED_01_state in the other.
I'm going to have to watch myself on that one.

But the code still doesn't work.

I have this logic.

if Button_1 is high, read set LEDs 1&2 high. Else set 1&2&3&4 low.

Which is where I'm screwed up.

Because I then have If button_2 is pressed WHILE button_1 is pressed, toggle from 1&2 to 3&4

But then I realize that button_1 will always override the button_2 function.

I'm just trying to figure out how to put them all together. It's a totally new, non linear, learning process.

(P.S. Why does the forum go down like it did this evening?)

I was drifting off to sleep last nigh (OK, this morning) when it dawned on me.
I have been approaching it wrong, all along

I wanted BTN_1 to turn on a state of the LEDs. And then I wanted BTN_2 to toggle the state of the LEDs.

So instead of doing them in two separate functions I should put them in the same function. And set the original state of the toggle from BTN_2 to HIGH.

if BTN_1 = HIGH
Go to function of BTN_2

else, all LEDs are LOW

Simple logic.

Now for the final piece of the puzzle before I clean up the code...

I have a weird situation.

My main function of the sketch requires

  digitalWrite (LED_01, LED_01_state);
  digitalWrite (LED_02, LED_02_state);
  digitalWrite (LED_03, LED_03_state);
  digitalWrite (LED_04, LED_04_state);

  digitalWrite (LED_07, LED_07_state);
  digitalWrite (LED_08, LED_08_state);
  
  digitalWrite (LED_05, LED_05_state);
  digitalWrite (LED_06, LED_06_state);
  digitalWrite (LED_09, LED_09_state);
  digitalWrite (LED_10, LED_10_state);

To be in the void loop.

But for the toggle of BTN_2 to work it requires

  digitalWrite (LED_05, LED_05_state);
  digitalWrite (LED_06, LED_06_state);
  digitalWrite (LED_09, LED_09_state);
  digitalWrite (LED_10, LED_10_state);

To be in the void setup.

So, what's the problem ?

By the way. Please stop annoying me (and I suspect others) by referring to "the void loop" and "the void setup". There are no such things. They are the loop function and the setup function respectively. The qualifier before the name refers to the type of variable that they will return when called. void indicates that they will not return a variable even if they were called, which your program should not normally do. Behind the scenes they are, in fact, called but that is another matter.

UKHeliBob:
So, what's the problem ?

I'm not sure what you are asking is a direction for me to figure it out or that you didn't understand that I can't have BOTH of those lines in the loop and setup and have them both work.

UKHeliBob:
By the way. Please stop annoying me (and I suspect others) by referring to "the void loop" and "the void setup". There are no such things. They are the loop function and the setup function respectively. The qualifier before the name refers to the type of variable that they will return when called. void indicates that they will not return a variable even if they were called, which your program should not normally do. Behind the scenes they are, in fact, called but that is another matter.

I use those terms as "sections of the sketch" as opposed to the "functions" when describing them. If it is so annoying I will endeavor to stop adding the word "void" but rest assured, in my head I will be saying "void" because I am describing an area of a sketch.

I still don't see the problem.

The code in the setup() function runs once. The code in the loop() function may run many times. So what ?
You could turn an LED on or off in setup() to give it an initial state then change it as many times as you like in loop()

// using If .. else

byte BTN_1 = 8; // Button pin 1
byte BTN_2 = 9; // Button pin 2
byte LED_1 = 10; // Led 1
byte LED_2 = 11; // Led 2
byte LED_3 = 12; // Led 3
byte LED_4 = 13; // Led 4

void setup(){
  pinMode(BTN_1, INPUT);
  digitalWrite(BTN_1, HIGH); // Enable pull-up
  pinMode(BTN_2, INPUT);
  digitalWrite(BTN_2, HIGH); // Enable pull-up
  
  pinMode(LED_1, OUTPUT);
  pinMode(LED_2, OUTPUT);
  pinMode(LED_3, OUTPUT);
  pinMode(LED_4, OUTPUT);
}

void loop(){
  if(digitalRead(BTN_1) == LOW){     // Button pin 1 is pressed
   if(digitalRead(BTN_2) == LOW){    // Button pin 2 is pressed
     digitalWrite(LED_1, LOW);
     digitalWrite(LED_2, LOW);
     digitalWrite(LED_3, HIGH);
     digitalWrite(LED_4, HIGH);
   }
   else{                 // Button pin 2 is not pressed
     digitalWrite(LED_1, HIGH);
     digitalWrite(LED_2, HIGH);
     digitalWrite(LED_3, LOW);
     digitalWrite(LED_4, LOW);
   }
  }
  else{                  // Botton pin 1 is not pressed
     digitalWrite(LED_1, LOW);
     digitalWrite(LED_2, LOW);
     digitalWrite(LED_3, LOW);
     digitalWrite(LED_4, LOW);
   }
}
// using switch case

byte BTN_1 = 8; // Button pin 1
byte BTN_2 = 9; // Button pin 2
byte LED_1 = 10; // Led 1
byte LED_2 = 11; // Led 2
byte LED_3 = 12; // Led 3
byte LED_4 = 13; // Led 4

byte mode = 0;

void setup(){
  pinMode(BTN_1, INPUT);
  digitalWrite(BTN_1, HIGH); // Enable pull-up
  pinMode(BTN_2, INPUT);
  digitalWrite(BTN_2, HIGH); // Enable pull-up
  
  pinMode(LED_1, OUTPUT);
  pinMode(LED_2, OUTPUT);
  pinMode(LED_3, OUTPUT);
  pinMode(LED_4, OUTPUT);
}

void loop(){
  if(digitalRead(BTN_1)==HIGH){mode = 0;}
  if(digitalRead(BTN_1)==LOW and digitalRead(BTN_2) == HIGH){mode = 1;}
  if(digitalRead(BTN_1)==LOW and digitalRead(BTN_2) == LOW){mode = 2;}
  
  switch(mode){
    
    case (0):
     digitalWrite(LED_1, LOW);
     digitalWrite(LED_2, LOW);
     digitalWrite(LED_3, LOW);
     digitalWrite(LED_4, LOW);
     break;
    
    case (1):
     digitalWrite(LED_1, HIGH);
     digitalWrite(LED_2, HIGH);
     digitalWrite(LED_3, LOW);
     digitalWrite(LED_4, LOW);
     break;
    
    case(2):
     digitalWrite(LED_1, LOW);
     digitalWrite(LED_2, LOW);
     digitalWrite(LED_3, HIGH);
     digitalWrite(LED_4, HIGH);
     break;
  }
}

-Fletcher

Thanks but it looks like that just toggles the LEDs on or off each time the switch is ON, as long as the other switch is ON.
I need it to be ON with switch ONE and then just toggle from one LEDs (set) the the other when switch TWO is momentarily pressed, leaving the LEDs in that state..

OK, I think I've got it. I spent the last few days trying to run different logic in the back of my head and it finally clicked.

Here's my code, so far

const int buttonPina = 3;   // the number of the pushbutton pin #6
const int buttonPin = 4;    // the number of the pushbutton pin #7
const int ledPin01 = 5;      // the number of the LED pin
const int ledPin03 = 6;
const int ledPin02 = 19;
const int ledPin04 = 18;


// Variables will change:
int ledState01 = HIGH;         // the current state of the output pin
int ledState02 = LOW;
int ledState03 = HIGH;
int ledState04 = LOW;
int buttonState = LOW;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 250;    // the debounce time; increase if the output flickers

void setup() {
  delay (500);
  pinMode(buttonPina, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin01, OUTPUT);
  pinMode(ledPin02, OUTPUT);
  pinMode(ledPin03, OUTPUT);
  pinMode(ledPin04, OUTPUT);

//   int ledState01 = LOW;        // the current state of the output pin
//   int ledState02 = LOW;
//   int ledState03 = LOW;
//   int ledState04 = LOW;

  // set initial LED state
  digitalWrite(ledPin01, ledState01);
  digitalWrite(ledPin02, ledState02);
  digitalWrite(ledPin03, ledState03);
  digitalWrite(ledPin04, ledState04);  
}
//while(digitalRead(buttonPin) ) { }
void loop(){ 
  if( digitalRead(buttonPina)==HIGH )
  
{
  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
}
  
  

}
}
else if ( digitalRead(buttonPina)==LOW)
  {
    digitalWrite(ledPin01,LOW); //Turns off LED01 if it was on
    digitalWrite(ledPin02,LOW);  //Turns on LED02 if it was off
    digitalWrite(ledPin03,LOW); //Turns on LED03 if it was off
    digitalWrite(ledPin04,LOW);  //Turns off LED04 if it was on
  
}
}

I am sure there is room for improvement, including but the code works, except for one thing.

Right now, when I upload the code (or reset the Arduino) all four LEDs come of until I hit buttonPina AND buttonPin and then everything functions as I want it to.

Any help in setting two LEDs high as an initial state WHEN I PUSH buttonPna without destroying the rest of the function would be appreciated.

I just updated this post.

I am sure there is room for improvement

One area I see is that what you write to the pins, and what you store in the variables, are duplicated. Use the value in the variable in the digitalWrite() call, and there is no possibility of the variable and the pin getting out of sync.

Another area is that you are using +1 and -1 for the values, instead of HIGH or LOW.

pinState = !pinState;

toggles the value from HIGH to LOW or from LOW to HIGH

I do wish that the consistent placement of { (preferably on lines by themselves) and proper indenting (or Tools + Auto Format) would click, too..

OK, no more +1 and -1 for values - CHECK
Formatted using auto format - CHECK (which I didn't realize was an option after you typed code)

Now here is what I have for code

const int buttonPina = 3;   // the number of the pushbutton pin #6
const int buttonPin = 4;    // the number of the pushbutton pin #7
const int ledPin01 = 5;      // the number of the LED pin
const int ledPin03 = 6;
const int ledPin02 = 19;
const int ledPin04 = 18;


// Variables will change:
int ledState01 = HIGH;         // the current state of the output pin
int ledState02 = LOW;
int ledState03 = HIGH;
int ledState04 = LOW;
int buttonState = LOW;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 250;    // the debounce time; increase if the output flickers

void setup() {
  delay (500);
  pinMode(buttonPina, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin01, OUTPUT);
  pinMode(ledPin02, OUTPUT);
  pinMode(ledPin03, OUTPUT);
  pinMode(ledPin04, OUTPUT);

  //   int ledState01 = LOW;        // the current state of the output pin
  //   int ledState02 = LOW;
  //   int ledState03 = LOW;
  //   int ledState04 = LOW;

  // set initial LED state
  digitalWrite(ledPin01, ledState01);
  digitalWrite(ledPin02, ledState02);
  digitalWrite(ledPin03, ledState03);
  digitalWrite(ledPin04, ledState04);  
}
//while(digitalRead(buttonPin) ) { }
void loop(){ 
  if( digitalRead(buttonPina)==HIGH )

  {
    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
      }
    }
  }
  else if ( digitalRead(buttonPina)==LOW)
  {
    digitalWrite(ledPin01,LOW); //Turns off LED01 if it was on
    digitalWrite(ledPin02,LOW);  //Turns on LED02 if it was off
    digitalWrite(ledPin03,LOW); //Turns on LED03 if it was off
    digitalWrite(ledPin04,LOW);  //Turns off LED04 if it was on

  }
}

I tried various configurations where I used "ledState" instead of "ledPin" and none produced results that were desirable.

Now my sketch yields the following

Reset Arduino - two leds light for about a millisecond and go off.
I press and hold buttonPina and nothing changes (this is where I'd like to have two LEDs light up)
I momentarily press buttonPin and two LEDs light up. If I release buttonPin the LEDs will stay in the state they were in last (this is the desired effect.
If I hold buttonPin down, the two sets of LEDs will toggle back and forth as long as buttonPin stays depressed (this is acceptable but not the true desired effect)
If I release buttonPina, all LEDs go off. (this is the desired effect.

All I really need, at this point, is a way to make all of the LEDs off when the board is reset and then come on as soon as buttonPina is pressed, otherwise it can behave the way it does now.

but rest assured, in my head I will be saying "void" because I am describing an area of a sketch.

The void in your head ? Apt !

Vaclav:
Since you advertizing yourself as a hobbyist I would like to give you few pointers.
In electronics there are few terms - one of them is "active (state)".
Buttons are generally active when low or ground or 0 voltage. In Arduino the button is connected to input pin and using internal pull up resistor to have the inactive state or idle state high or 5V.
To process button which is active you can simply use if(! digitalRead(button)).......
The LED "active" state is high or 5V so you set it using digitalWrite(pin, HIGH) = on ....or LOW = off.
To keep tract of the LED you just set the LED state variable to HIGH , or to reset it set the state to LOW.
Two or three "problems" with you code - compare states to low or high - not to zero.
Simplify your code to control ONE button and ONE LED and make ti play the way you want it.
Forget the debouncing for now, it really distracts from the program logic and makes it complicated.
Use delay to see your code working. Remember the Loop is infinite so slow it down when appropriate.
Check out Serial, it is a reasonable tool for checking your code flow. But use it sparingly, it can muck-up things up in a hurry.

Thanks for the input.
I am using the command to compare to zero because it simply doesn't work at all if I compare to HIGH or LOW. I don't know why, either.

I can't simplify my code because the application will require two switches to work in the way I'm writing. The eventual mechanics work as follows.

Switch one comes on and two lights come on.
If you momentarily push button two then the first pair of lights go off and the second set comes on. If you momentarily push button two again it switches back to the first pair of lights.
And if you flip switch one off, everything goes off.

THink of it as a headlight High/Low system because that's how it will behave.

I've tried the code without the first switch and everything functions fine. I can turn on and off LEDs with inputs with no trouble.
I just can't seem to get these two LEDs to turn on with switch one without also activating switch two. Switch two is just supposed to toggle between "states" which I'm also understanding.

It's the language and structure I'm having issues with.

Everything in my head is telling me I'm not seeing something obvious but I've tried all kinds of structural variations with no luck. Anything I try at this point just makes it worse.

OK, I figured out why it only worked with the zero reference. I was editing the wrong saved sketch.
It now works with the "HIGH"/"LOW" reference but still doesn't start the LEDs ON with the first button

Here's my code now

const int buttonPina = 3;   // the number of the pushbutton pin #6
const int buttonPin = 4;    // the number of the pushbutton pin #7
const int ledPin01 = 5;      // the number of the LED pin
const int ledPin03 = 6;
const int ledPin02 = 19;
const int ledPin04 = 18;


// Variables will change:
int ledState01 = HIGH;         // the current state of the output pin
int ledState02 = LOW;
int ledState03 = HIGH;
int ledState04 = LOW;
int buttonState = LOW;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 250;    // the debounce time; increase if the output flickers

void setup() {
  delay (500);
  pinMode(buttonPina, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin01, OUTPUT);
  pinMode(ledPin02, OUTPUT);
  pinMode(ledPin03, OUTPUT);
  pinMode(ledPin04, OUTPUT);

  //   int ledState01 = LOW;        // the current state of the output pin
  //   int ledState02 = LOW;
  //   int ledState03 = LOW;
  //   int ledState04 = LOW;

  // set initial LED state
  digitalWrite(ledPin01, ledState01);
  digitalWrite(ledPin02, ledState02);
  digitalWrite(ledPin03, ledState03);
  digitalWrite(ledPin04, ledState04);  
}
//while(digitalRead(buttonPin) ) { }
void loop(){ 
  if( digitalRead(buttonPina)==HIGH )

  {
    buttonState = digitalRead(buttonPin);

    if( (millis() - lastDebounceTime) > debounceDelay) {

      if ( (buttonState == HIGH) && (ledState01 == LOW) ){
        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 == HIGH) ){
        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
      }
    }
  }
  else if ( digitalRead(buttonPina)==LOW)
  {
    digitalWrite(ledPin01,LOW); //Turns off LED01 if it was on
    digitalWrite(ledPin02,LOW);  //Turns on LED02 if it was off
    digitalWrite(ledPin03,LOW); //Turns on LED03 if it was off
    digitalWrite(ledPin04,LOW);  //Turns off LED04 if it was on

  }
}

Just for my clarity. You say this:

And if you flip switch one off

... then this:

the first button

Is that a toggle switch that stays in one place when you flip it (like a house light switch) or is it a momentary button (like a car horn)?

And just for certainty, the second switch, what's it?

Bittsen:
OK, I figured out why it only worked with the zero reference. I was editing the wrong saved sketch.
It now works with the "HIGH"/"LOW" reference but still doesn't start the LEDs ON with the first button

If it would make it any easier for you, you can always define new terms for your buttons or LEDs.

For example, depending on whethe your LEDs light with a HIGH or LOW, you can define something like this...

#define OFF LOW
#define ON HIGH

or

#define OFF HIGH
#define ON LOW

or for buttons

#define PRESSED LOW
#define NOTPRESSED HIGH

for a toggle switch

#define UP LOW

And so on.