'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
current_position = 0
'buttons
BUT1 = 32 : BUT2 = 33 : BUT3 = 25 : BUT4 = 26
pin.mode BUT1, input,pullup
pin.mode BUT2, input,pullup
pin.mode BUT3, input,pullup
pin.mode BUT4, input,pullup
maxscroll.setup 8, 21
maxscroll.print "PRESS BUTT"
maxscroll.show 63, 5
pause 1000
interrupt BUT1, press1
interrupt BUT2, press2
interrupt BUT3, press3
interrupt BUT4, press4
wait
press1:
pulse_motor 0
return
press2:
pulse_motor 50
return
press3:
pulse_motor 100
return
press4:
pulse_motor 150
return
sub pulse_motor(pos)
maxscroll.print "POS " + str$(pos)
maxscroll.show 63,5
local c, z, dir
c = current_position - pos
if (c > 100) then c=100-c
if (c <-100) then c=-(c+100)
if (c < 0) then dir=1 else dir=0
pin(DIRECTION) = dir
for z = 1 to abs(c)
pin(STEPS) = 1
pin(STEPS) = 0
pause 10
next z
current_position = pos
end sub