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