This should go left with one button, go right with the other button, and if no buttons are pressed, should 'walk' back to center.Code:@ device HS_OSC,MCLR_OFF,LVP_OFF,WDT_OFF,PROTECT_OFF DEFINE OSC 4 'Use b1 to hold pulse width variable for servo 1 b1 var byte 'initialize variables b1 = 150 low portb.0 ' put the servoport low. main: low portb.0 pulsout portb.0, b1 'send current servo 1 position out if porta.0 = 0 then left1 'check for pressed switch 0 if porta.1 = 0 then right1 'check for pressed switch 1 if b1 > 150 then b1 = b1 - 1 else b1 = b1 + 1 endif pause 18 : goto main left1: b1 = b1 + 1 : if b1 >254 then max1 goto main right1: b1 = b1 - 1 : if b1 <75 then min1 goto main max1: b1 = 75 : goto main min1: b1 = 254 : goto main END
Note the BOLDED statements
Bookmarks