Button pressing order

Hi. Im new here.

I have Buttons - A,B,C,D and reset button

I need to read button combinations and activate outputs accordingly. I have a working program for the combination A-B and B-A. After pressing the reset button, the outputs turn off. It works, but I am unable to add more button combinations. Here is the function code for buttons A and B. Other necessary combinations are A-C, C-A, A-D, D-A

I'm not a programmer, so I apologize.

const int buttonPin1 = 21; //Button A
const int buttonPin2 = 22; //Button B
const int outPut1 = A1; 
const int outPut2 = A9; 
const int resetButton = 20; 
const int activeLED = 42; 

int var1; 
int var2; 
int lastButtonState1 = 1;
int lastButtonState2 = 1;
int lastButtonState3 = 1;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int active = 0;
int reset = 0;



void setup() {
 pinMode (buttonPin1, INPUT_PULLUP);
 pinMode (buttonPin2, INPUT_PULLUP);
 pinMode (outPut1,  OUTPUT);
 pinMode (outPut2, OUTPUT);
 pinMode (resetButton, INPUT_PULLUP);
 pinMode (activeLED, OUTPUT);
 digitalWrite(outPut1, HIGH);
 digitalWrite(outPut2, HIGH);

}

void loop() {
 buttonState1 = digitalRead(buttonPin1); 
 buttonState2 = digitalRead(buttonPin2);
 buttonState3 = digitalRead(resetButton);

  if (buttonState1 != lastButtonState1 & var2 == 0 & active == 0) {  
    var1 = 1;}
  if (buttonState2 != lastButtonState2 & var1 == 1) {
  if (active == 0)    {
    digitalWrite(outPut1, LOW); 
    digitalWrite(activeLED, HIGH);
    active = 1;
    var1 = 0;
    delay(500);
    buttonState2 = 0;
    buttonState1 = 0;
    
    } }
    if (buttonState3 != lastButtonState3)
      {active = 0;
      digitalWrite(activeLED, LOW);
      digitalWrite(outPut1, HIGH);
      }
      
  
  if (buttonState2 != lastButtonState2 & var1 == 0 & active == 0) { 
    var2 = 1;}
  if (buttonState1 != lastButtonState1 & var2 == 1) {
  if (active == 0)
  {
    digitalWrite(outPut2, LOW);
    digitalWrite(activeLED, HIGH);
    active = 1;
    var2 = 0;
    delay(500);
    buttonState1 = 0;
    buttonState2 = 0;
    }
      
    }
    if (buttonState3 != lastButtonState3)
      {active = 0;
      digitalWrite(activeLED, LOW);
      digitalWrite(outPut2, HIGH);
      }}

Where did you find the current program and do you understand how it works?

Is it always a 2 button combination or can you have a 3/4 button combination too?

Are the buttons supposed to be pressed simultaneously or in sequence?

If simultaneously, I might consider reading the entire Port and then taking the nibble related to the buttons and run it through SELECT CASE type logic (or whatever the C equivalent to that is lol).

This code was written for me by a friend who knows at least a little programming, but he couldn't do much more. No, I don't understand the main parts where buttons are read and compared with variables.

Always two

So what are you expecting from the Arduino forum? Are you expecting someone the take the place of your friend and make changes to your code so you can test it and report back?

In sequence please

Ok so here is what you need to do. Change your code to read the buttons as an array. If any button is pressed, that button is stored as "firstPressed" you can store the pin number if you would like. Then once you have the first button, you then need to read your buttons again for the next button. If the first button is the same as the second button, skip it and keep waiting until the button is different. You may also want to debounce your buttons too.

Once you have 2 different buttons, you then do whichever logic is needed for them. You can use IF/ELSE statements or a SWITCH statement. A switch statement will be cleaner.
Finally once the combination is done, you reset both buttons.

Rinse and repeat

No messages back to anyone. I need to expand the code for use on a model railroad

Did you ever get the feeling that you were doing someone's homework for them lol ?

No homework, really

What is the 2 button requirement for?

No, but like many people I have worked with who do their best to get someone else to do their work!

Routing of trains from track A to tracks B,C and D. One combination, for example A-B switch one one polarity to tracks and combination B-A switch opposite polarity to tracks. Routing trans from point to point

I'm always overthinking my projects lol - you start with matching up last button with current button to get your 2 button code... But what happens if someone presses 3 buttons? Or one button and then forgets? I bet 50% of my code is guarding against bad user errors lol.

I don't know how to describe it from a railway environment for a normal person. Each combination activated by two buttons will have its own lock, the variable "active" if it has the value 1. No other commands should be accepted.

If I didn't delete it in anger, I'll try to find my idea of ​​a code for more combinations

Even you can't find it, I'm betting you can recreate it, and actually test it!

Thank you sou much for "kick forward"!