Turning motors on using buttons

I am making a vending machine and I have 4 motors and 4 buttons each controlling each other. I am using LED buttons and I think that it is not working how it should be. I did a test using serial monitor and its doing weird stuff that shouldn't be happening.

 #include <Servo.h>

#define button1 1
#define button2 2
#define button3 3
#define button4 4

Servo servo1, servo2, servo3, servo4;  


int buttonPressed; 

void setup () { 
  Serial.begin(9600);
  servo1.attach(17);
  servo2.attach(18);
  servo3.attach(19);
  servo4.attach(20);
  
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  pinMode(button4, INPUT_PULLUP);
  
}
void loop () {
  while (true) {
    if (digitalRead(button1) == LOW) {
      buttonPressed = 1;
      Serial.println("button pressed 1");
      
    }
    if (digitalRead(button2) == LOW) {
      buttonPressed = 2;
      Serial.println("button pressed 2");
     
    }
    if (digitalRead(button3) == LOW) {
      buttonPressed = 3;
      Serial.println("Button pressed3");
      
    }
    if (digitalRead(button4) == LOW) {
      buttonPressed = 4;
      Serial.println("Button pressed4");
      
    }
}
switch (buttonPressed) {
    case 1:
      
      servo1.writeMicroseconds(1000); // rotate
      delay(950);
      servo1.writeMicroseconds(1500);  // stop
    
      

     case 2:
      
      servo2.writeMicroseconds(1000); // rotate
      delay(950);
      servo2.writeMicroseconds(1500);  // stop
    
     
      
     case 3:
      
      servo3.writeMicroseconds(1000); // rotate
      delay(950);
      servo3.writeMicroseconds(1500);  // stop

   
      
     case 4:
      
      servo4.writeMicroseconds(1000); // rotate
      delay(950);
      servo4.writeMicroseconds(1500);  // stop
    
      
}
}

here is my discord username so I can show you a video and pics: harrry6153#9107

What shall happen?

switch (buttonPressed) {
    case 1:
      
      servo1.writeMicroseconds(1000); // rotate
      delay(950);
      servo1.writeMicroseconds(1500);  // stop
    
     case 2:

Whoops
No break; at the end of each case

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.