multi button state if else question

i am trying to run a function when one of 5 buttons are pressed but the functions just seem to run weather the buttons are pressed or not

// the number of the pushbutton pin  
const int buttonPin = 8;  
const int buttonPin1 = 9;
const int buttonPin2 = 10;
const int buttonPin3 = 11;
const int buttonPin4 = 12;

//Servo Pin
int servoPin=4;

// variables will change:  
int buttonState = LOW;
int buttonState1 = LOW;
int buttonState2 = LOW;
int buttonState3 = LOW;
int buttonState4 = LOW;
// variable for reading the pushbutton status 

#include <Servo.h>;
Servo Servo1;

void setup(){
  Servo1.attach(servoPin);

  // initialize the pushbutton pin as an input:  
  pinMode(buttonPin, INPUT);   
  pinMode(buttonPin1, INPUT); 
  pinMode(buttonPin2, INPUT);   
  pinMode(buttonPin3, INPUT); 
  pinMode(buttonPin4, INPUT); 
  
  // initialize serial communication:
  Serial.begin(9600);
  Servo1.write(90);
}

void loop() {
  halt();
 // read the state of the pushbutton value:  
   buttonState = digitalRead(buttonPin);  
   buttonState1 = digitalRead(buttonPin1);
   buttonState2 = digitalRead(buttonPin2);
   buttonState3 = digitalRead(buttonPin3);
   buttonState4 = digitalRead(buttonPin4);
     Serial.println("waiting for Press");
     
  // check if the pushbutton is pressed.  
  // if it is, the buttonState is HIGH:  
  
  if (buttonState1 == HIGH) {     
    // turn clockwise for 1 second:    
    cwf(); 
    Serial.println("clockwise button Pressed");
  }
  else
  {
  halt();
  }  
}

  // main funtions do not change
void cwf(){
        Serial.print("Going Clockwise Fast");
        Serial.println();
        Servo1.write(1);
        delay(1000);
        Serial.print("done");
        Serial.println();
}

void ccwf(){
        Serial.print("Going Counter Clockwise Fast");
        Serial.println();
        Servo1.write(180);
        delay(1000);
        Serial.print("done");
        Serial.println();
}

void cws(){
        Serial.print("Going Clockwise Slow");
        Serial.println();
        Servo1.write(87);
        delay(1000);
        Serial.print("done");
        Serial.println();
}

void ccws(){
        Serial.print("Going Counter Clockwise Slow");
        Serial.println();
        Servo1.write(93);
        delay(1000);
        Serial.print("done");
        Serial.println();
}

void halt () {
        Serial.print("Stopped");
        Serial.println();
        Servo1.write(90);
        delay(1);
        Serial.println();
}

i got this from a other site but tried to use it for my use but the 2 functions cwf() and halt() are just running even if no buttons are pressed. i have checked the connections of the buttons and they are fine

What value pull down resistors are installed with your switches?

What is halt() doing? I have not seen that before.

mikewitney wrote (iin part):

… and halt() are just running even if no buttons are pressed.

void loop() {
  halt();
...

The code is written so that halt() is going to run regardless of any buttons.

I notice you are using INPUT mode. Do you have pulldown resistors on all your buttons?

The usual way buttons are wired in arduino projects is that the pin has a pullup resistor on it, and the button causes the pin to be grounded to the chassis. That is - HIGH is off and LOW is on. Conveniently, pinMode(pin, INPUT_PULLUP) will attach an internal pullup resistor to a pin.

Without the resistor, when the button is open the pin is floating and may have residual voltage on it - static electricity, effectively.

Whatare those halts for? If they do what I think they do, unless you are holding down a button while you reset the arduino, the very first time the loop runs it will stop the processor.

PaulMurrayCbr wrote (in part):

unless you are holding down a button while you reset the arduino, the very first time the loop runs it will stop the processor.

Sorry, but the OP presented code that has the first halt() before the first if statement. halt() will be executed at least once regardless of any buttons being pressed.

groundfungus:
What value pull down resistors are installed with your switches?

What is halt() doing? I have not seen that before.

halt is just a function below all the code

vaj4088:
PaulMurrayCbr wrote (in part):

Sorry, but the OP presented code that has the first halt() before the first if statement. halt() will be executed at least once regardless of any buttons being pressed.

halt is the default mode if noting is pressed and halt should always be run first when the code runs

If you include all the code in your post we wouldn't have to ask.

Do your buttons have pulldown resistors?

groundfungus:
If you include all the code in your post we wouldn't have to ask.

Do your buttons have pulldown resistors?

yes i do have pull-down resistors on the buttons and i have added the complete code to the main post

So you are using a "continuous" servo? Have you confirmed that it stops with a setting of 90? Have you put a meter on the button input to confirm that it is changing state when pushed?