head scratching

hi people, first I would apologise for any bad practise,etc …new to this
I am having problems with this project, I borrowed the core of the programme, which is intended to display the current gear on a motorcycle, using a single 7 seg display, the original programme works to an extent, but it scrolls up through the gears without “incrementing” , I am using two microswitches which wiil mount to the gear selector , one for up , one for ,down and a connection to the neutral light for neutral(which on a bike is between 1 and 2 , not below 1,
im trying to make the programme wait for the microswitch to release before resuming to look for the next signal, but up to now the loop continuously cycles and scroll up and down constantly,
have rewritten the code and have come up against error codes… which im struggling to resolve, have copied and pasted the code for your amusement… be gentle lol I don’t know what im doing TIA

byte gear = 6;
int buttonpin1 = 10;
int buttonpin2 = 11;
int buttonpin3 = 12;

void setup() {
// // Define Pins
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(buttonpin1, INPUT_PULLUP);
pinMode(buttonpin2, INPUT_PULLUP);
pinMode(buttonpin3, INPUT_PULLUP);

// All leds test
digitalWrite(2, 1);
digitalWrite(3, 1);
digitalWrite(4, 1);
digitalWrite(5, 1);
digitalWrite(6, 1);
digitalWrite(7, 1);
digitalWrite(8, 1);
delay(1000);
digitalWrite(2, 0);
digitalWrite(3, 0);
digitalWrite(4, 0);
digitalWrite(5, 0);
digitalWrite(6, 0);
digitalWrite(7, 0);
digitalWrite(8, 0);
delay(1000);
}
void loop() {
int buttonstate1 = digitalRead(buttonpin1);
int buttonstate2 = digitalRead(buttonpin2);
int buttonstate3 = digitalRead(buttonpin3);
int gear;
if (gear == 6) {
//set LED values
if (buttonstate1 == HIGH) {
gear = 0;
}
} else {
if (buttonstate2 == HIGH) {

if (gear == 0) {
gear = 2; //shift up from neutral to 2nd
} else if (gear == 1) {
//do nothing check for pin 10 later
} else if (gear < 5) {
gear = gear + 1; //shift up from any other gear
}
} while (buttonstate2 == HIGH); {
}

if (buttonstate3 == HIGH) {
}
if (gear == 2) {

//do nothing check for pin 10 later
} else if (gear == 0) {
gear = 1; //shift down from neutral into 1st

} else if (gear > 1) {
gear = gear - 1;
} else if (gear == 1) {
//do nothing check for pin 10 lat

}else if(buttonstate1 == HIGH); && (gear == 2 || gear == 1); {gear = 0);{
}
} while (buttonstate3 == HIGH); { // check for neutral

}
updateLED();

delay(100);
}
}
void updateLED() {
switch (gear) {
case 0:
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
break;
case 1:
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
break;
case 2:
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
break;
case 3:
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
break;
case 4:
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
break;
case 5:
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
break;

}
}

byte gear = 6;
int buttonpin1 = 10;
int buttonpin2 = 11;
int buttonpin3 = 12;

void setup() {
  //   // Define Pins
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(buttonpin1, INPUT_PULLUP);
  pinMode(buttonpin2, INPUT_PULLUP);
  pinMode(buttonpin3, INPUT_PULLUP);

  // All leds test
  digitalWrite(2, 1);
  digitalWrite(3, 1);
  digitalWrite(4, 1);
  digitalWrite(5, 1);
  digitalWrite(6, 1);
  digitalWrite(7, 1);
  digitalWrite(8, 1);
  delay(1000);
  digitalWrite(2, 0);
  digitalWrite(3, 0);
  digitalWrite(4, 0);
  digitalWrite(5, 0);
  digitalWrite(6, 0);
  digitalWrite(7, 0);
  digitalWrite(8, 0);
  delay(1000);
}
void loop() {
  int buttonstate1 = digitalRead(buttonpin1);
  int buttonstate2 = digitalRead(buttonpin2);
  int buttonstate3 = digitalRead(buttonpin3);
  int gear;
  if (gear == 6) {
    //set LED values
    if (buttonstate1 == HIGH) {
      gear = 0;
    }
  } else {
    if (buttonstate2 == HIGH) {

      if (gear == 0) {
        gear = 2;  //shift up from neutral to 2nd
      } else if (gear == 1) {
        //do nothing check for pin 10 later
      } else if (gear < 5) {
        gear = gear + 1; //shift up from any other gear
      }
    } while (buttonstate2 == HIGH); {
    }


    if (buttonstate3 == HIGH) {
    }
    if (gear == 2) {

      //do nothing check for pin 10 later
    } else if (gear == 0) {
      gear = 1; //shift down from neutral into 1st

    } else if (gear > 1) {
      gear = gear - 1;
    } else if (gear == 1) {
      //do nothing check for pin 10 lat

  }else if(buttonstate1 == HIGH); && (gear == 2 || gear == 1); {gear = 0);{
}
 } while (buttonstate3 == HIGH); { //  check for neutral
   
  }
updateLED();


delay(100);
}
}
void updateLED() {
  switch (gear) {
    case 0:
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      digitalWrite(7, LOW);
      digitalWrite(8, HIGH);
      break;
    case 1:
      digitalWrite(2, LOW);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      digitalWrite(7, LOW);
      digitalWrite(8, LOW);
      break;
    case 2:
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, HIGH);
      digitalWrite(6, HIGH);
      digitalWrite(7, LOW);
      digitalWrite(8, HIGH);
      break;
    case 3:
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      digitalWrite(7, LOW);
      digitalWrite(8, HIGH);
      break;
    case 4:
      digitalWrite(2, LOW);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      break;
    case 5:
      digitalWrite(2, HIGH);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      break;

  }
}

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\David\Documents\Arduino\gear_indicator_2\gear_indicator_2.ino: In function 'void loop()':

gear_indicator_2:75:38: error: expected identifier before '(' token

}else if(buttonstate1 == HIGH); && (gear == 2 || gear == 1); {gear = 0);{

^

gear_indicator_2:75:73: error: expected ';' before ')' token

}else if(buttonstate1 == HIGH); && (gear == 2 || gear == 1); {gear = 0);{

^

exit status 1
expected identifier before '(' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

if(buttonstate1 == HIGH); && Semicolon oops

yeah im scratching my head looking at this too. Its very hard to read. first thing you should do is get things organized.

if you use loops and arrays it will make things much more organized and make it easier to change and adjust things.

a put your code into clean sections for you.

all the light patterns are in a organized section you can change at the top.
you will have to change them to what you want.

when checking buttons i added a variables that remember the previos state of the the buttons. this way if the new pin reading does not match the old, you can detect the change.
Also i thought that if your using INPUT_PULLUP that the button down produces LOW??? i dont know your wiring but you might need to change that.

the button presses are sent to a function. here you will have to make changes regarding what the buttons do to the gear.

but here is an organizational system that I think will make things easier for you.
if you have any questions let me know. if you dont know about loops and arrays please take the time to learn. they are super cool and you can do many things you normally couldnt!

int i;
int buttonpins[3] = {10,11,12};
int lightpins[8]  = {2,3,4,5,6,7,8,9};
bool pushed[3];
bool last[3];
int gear;

    // define all light patterns
int patterns[8][8]={
    {0,0,1,0,1,0,1,1},//gear 0
    {0,0,0,0,1,0,0,1},//gear 1
    {0,0,1,1,1,0,1,1},//gear 2
    {0,0,1,0,1,1,1,1},//gear 3
    {1,0,1,0,1,0,1,1},//gear 4
    {0,0,1,1,1,1,1,1},//gear 5
    {0,0,0,0,0,0,0,0},//all off
    {1,1,1,1,1,1,1,1},//all on
};
void setup() {
     // Define Pins
     for(i=0; i<8; i++){ pinMode(lightpins[i], OUTPUT); }
     for(i=0; i<3; i++){pinMode(buttonpins[i], INPUT_PULLUP); }
    // All leds test
 updateLED(7); delay(1000);  updateLED(6); delay(1000);
}
void loop() {
  // read all buttons and check for change
  for(int i=0; i<3; i++){bool b = false;
  pushed[i] = digitalRead(buttonpins[i]);
  if(pushed[i]!=last[i]){last[i] = pushed[i];
 // might need to change this next line to check for LOW?????
  if(pushed[i]==HIGH){gotbutton(i);}}}
  delay(3);
}

void gotbutton(int p){
    // this function is only called once everytime a botton goes down
    if(p==1){if (gear<5){gear++;}}
    if(p==2) {gear = 0;}
    if(p==3) {if(gear>0){gear--;}}
    
    updateLED(gear);}

void updateLED(int p){
     // this function lights your leds according to the patterns at the top
      for(int i=0; i<8; i++){
      digitalWrite(lightpins[i], patterns[i]);
    }
  
}

taterking:
yeah im scratching my head looking at this too. Its very hard to read.

…so you thought you’d make it even harder?

void loop() {
  // read all buttons and check for change
  for(int i=0; i<3; i++){bool b = false;
  pushed[i] = digitalRead(buttonpins[i]);
  if(pushed[i]!=last[i]){last[i] = pushed[i];
 // might need to change this next line to check for LOW?????
  if(pushed[i]==HIGH){gotbutton(i);}}}
  delay(3);
}

Hint: Like "???", “}}}” should never happen.

It really helps to use readable names for inputs. And switch inputs should have state change detection, otherwise they might get counted multiple times on one activation.

enum Gears {Neutral, First, Second, Third, Fourth, Fifth} Gear = Neutral;
const byte NeutralPin = 10;
const byte ShiftUpPin = 11;
const byte ShiftDownPin = 12;


void setup()
{
  //   // Define Pins
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);


  pinMode(NeutralPin, INPUT_PULLUP);
  pinMode(ShiftUpPin, INPUT_PULLUP);
  pinMode(ShiftDownPin, INPUT_PULLUP);


  // All leds test
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  delay(1000);
}


void loop()
{
  boolean inNeutral = digitalRead(NeutralPin) == LOW;


  static boolean lastShiftUpState = false;
  boolean shiftUpState = digitalRead(ShiftUpPin) == LOW;


  static boolean lastShiftDownState = false;
  boolean shiftDownState =  digitalRead(ShiftDownPin) == LOW;


  if (inNeutral)
  {
    Gear = Neutral;
    updateLED();
    return; // Nothing more to do but check inputs again
  }


  if (shiftUpState && !lastShiftUpState) // Shifting Up
  {
    switch (Gear)
    {
      case First:   Gear = Second; break;  // Full shift
      case Neutral: Gear = Second; break;  // Half shift
      case Second:  Gear = Third; break;
      case Third:   Gear = Fourth; break;
      case Fourth:  Gear = Fifth; break;
      case Fifth:   break; // Do nothing
    }
    updateLED();
  }
  lastShiftUpState = shiftUpState;




  if (shiftDownState && !lastShiftDownState) // Shifting Down
  {
    switch (Gear)
    {
      case Fifth:   Gear = Fourth; break;
      case Fourth:  Gear = Third; break;
      case Third:   Gear = Second; break;
      case Second:  Gear = First; break;  // Full shift
      case Neutral: Gear = First; break;  // Half shift
      case First:   break;  // Do nothing
    }
    updateLED();
  }
  lastShiftDownState = shiftDownState;




}


void updateLED()
{
  switch (Gear)
  {
    case Neutral:
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, HIGH);
      digitalWrite(7, LOW);
      digitalWrite(8, HIGH);
      break;


    case First:
      digitalWrite(2, LOW);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      digitalWrite(7, LOW);
      digitalWrite(8, LOW);
      break;


    case Second:
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      digitalWrite(5, HIGH);
      digitalWrite(6, HIGH);
      digitalWrite(7, LOW);
      digitalWrite(8, HIGH);
      break;


    case Third:
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      digitalWrite(7, LOW);
      digitalWrite(8, HIGH);
      break;


    case Fourth:
      digitalWrite(2, LOW);
      digitalWrite(3, HIGH);
      digitalWrite(4, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      break;


    case Fifth:
      digitalWrite(2, HIGH);
      digitalWrite(3, LOW);
      digitalWrite(4, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, LOW);
      digitalWrite(7, HIGH);
      digitalWrite(8, HIGH);
      break;
  }
}