'this simple code drives a servo
' a complete help of Annex32 can be found here
' https://cicciocb.com/annex32help/V1.442/
DIRECTION = 2 : STEPS = 15
pin.mode DIRECTION, output 'dir
pin.mode STEPS, output 'step
timer0 100, getJOY
pwm.setup STEPS, OFF
freq_p = -1
wait
getJOY:
v = adc(34)
' computes the
ratio = (v - 2048)/2048
freq = abs(ratio * 100)
dir = ratio > 0
pin(DIRECTION) = dir
print ratio, freq
if abs(ratio) < 0.1 then
pwm.setup STEPS, OFF
else
if (freq_p <> freq) then
pwm.setup STEPS, 1, 100, freq, 12
freq_p = freq
endif
end if
return