/* Set a speed value between 0 to 255 for each variablespeed_value1,speed_value2,speed_value3*/if(digitalRead(2)==HIGH){// Pin - o/p to the motor from any of the PWM pin.analogWrite(Pin,speed_value1);}if(digitalRead(3)==HIGH){analogWrite(Pin,speed_value2);}if(digitalRead(4)==HIGH){analogWrite(Pin,speed_value3);}
Refer : Servo control by push button switch arduino
/* Set a speed value between 0 to 255 for each variable speed_value1,speed_value2,speed_value3*/ if (digitalRead(2) == HIGH) { // Pin - o/p to the motor from any of the PWM pin. analogWrite(Pin, speed_value1); } if (digitalRead(3) == HIGH) { analogWrite(Pin, speed_value2); } if (digitalRead(4) == HIGH) { analogWrite(Pin, speed_value3); }