Manual Servo Control

Our next program will allow you to control the direction of the servo manually via a SPDT switch (with a center-off position) connected to ports B1 and B2. Without a center-off position, you will have to use two switches. A schematic is shown in figure 3 (below).

1490 Digital Compass

With the switch in the center position, the servo will not turn. When it is moved into forward, it will turn one way. Moving the switch down will make it turn the opposite direction. This program as-is will limit rotation to 45 degrees off-center, but can be modified to extend rotation through the aforementioned methods.

Listing 2

' Manual control of servo direction via
' an SPDT switch.
Symbol B1=pw
pw = 150
check: if pin1 = 0 then left
if pin2 = 0 then right
Pulsout 0,pw
pause 18
goto check
left: pw = pw + 1
pulsout 0,pw
pause 18
if pw > 200 then max
goto check
right: pw = pw - 1
pulsout 0,pw
pause 18
if pw < 100 then min
goto check
max: pw = 200
goto check
min: pw = 100
goto check



' create a variable pw
' begin at center position
' is pin 1 active?
' is pin 2 active?
' send current pw
' set frequency to about 50 Hz
' check again
' increase pulsewidth
' send current pw
' set frequency to about 50 Hz
' dont go over 2 ms
' go back and check again
' decrease pulsewidth
' send current pw
' set frequency to about 50 Hz
' dont go under 1 ms
' check again
' cap pw at 2 ms
' check again
' cap at 1 ms
' check again


End of Listing 2

Previous Page    Previous Page    Next Page