simple question

I'm new to the Arduino. i've got a few servos and pushbuttons hooked up to it, and i'm wondering how i can put the servo in one position, then wait for another button to be pressed, then put the servo back in another position (put simply)...

VAL5 = digitalRead(inPin5);//button 1, if ele is @ floor 2
if (VAL5 == HIGH) {
pulseWidth3 = (22 * 9) + minPulse;//deactivate up restrict (make sure)
pulseWidth4 = (130 * 9) + minPulse;//deactivate down restrict (make sure)
pulseWidth1 = (40 * 9) + minPulse;
pulseWidth2 = (160 * 9) + minPulse;//open cw <---------------moving the servo
VAL4 - digitalRead(inPin4);
if (VAL4 == HIGH) { <--------------when the switch is hit
pulseWidth2 = (20 * 9) + minPulse;//when ele reaches bottom, close cw <---------------putting the servo back

if anyone can understand what i'm saying please help :stuck_out_tongue:

was this a typo?
VAL4 - digitalRead(inPin4);

try:
VAL4 = digitalRead(inPin4);
if (VAL4 == HIGH) { <--------------when the switch is hit
pulseWidth2 = (20 * 9) + minPulse;//when ele reaches bottom, close cw

thanks haha never would have noticed that :expressionless:

any other tips are welcome too :smiley:

These suggestions are stylistic and subject to personal preference so feel free to ignore them if you want.

 #define BTN_FLOOR_ONE 4 // this was inPin4
 #define BTN_FLOOR_TWO 5 // this was inPin5
 
 #define minPulse 1000
 #define DEACTIVATE_UP   ((22 * 9) + minPulse)
 #define DEACTIVATE_DOWN ((130 * 9) + minPulse)
 #define OPEN_CCW        ((40 * 9) + minPulse)  
 #define OPEN_CW         ((160 * 9) + minPulse)
 #define CLOSE_CCW       ((? * 9) + minPulse)  
 #define CLOSE_CW        ((20 * 9) + minPulse)
 
 
    if (digitalRead(BTN_FLOOR_TWO)== HIGH) { 
       pulseWidth3 = DEACTIVATE_UP;     
       pulseWidth4 = DEACTIVATE_DOWN;  
       pulseWidth1 = CLOSE_CW; 
       pulseWidth2 = OPEN_CW; 
    }
    else if( digitalRead(BTN_FLOOR_ONE) == HIGH)
    {                
       pulseWidth2 = CLOSE_CW; //when ele reaches bottom, close cw <--putting the servo back 
    }

I like to #define constants with meaningful names. And the names are more helpful if they evoke the functional purpose of the value.
For example, BTN_FLOOR_ONE can be more expressive than inPin4.

Also, you can eliminate the variables VAL4 and VAL5 and use the digitalRead directly.

I hope that helps. have fun

Thanks