aUCBLogo Demos and Tests / steppermotor2
be steppermotor2
adr=888
state=0
steps=64
speed=50000
print [If a stepper motor is connected be bit 0..3 of the parallel port]
print [then + F2 F3 F4 \ F5 F6 F7 - are the driving keys]
print [ESC stops]
running=true
while [running]
[ ch=readChar
if ch==char 27 [running=false]
if ch=="+ [drive steps]
if ch=="- [drive -steps]
if ch==char 255
[ ch=readCharExt
case ch
[ [WXK_F1 drive -steps]
[WXK_F2 drive lshift -steps -2]
[WXK_F3 drive lshift -steps -4]
[WXK_F4 drive lshift -steps -6]
[WXK_F5 drive lshift steps -6]
[WXK_F6 drive lshift steps -4]
[WXK_F7 drive lshift steps -2]
[WXK_F8 drive steps]
]
]
]
PortOut adr 255
be drive steps
ifelse steps < 0
[ drivebackward -steps
][ driveforward steps
]
end
be driveforward steps
if steps==0 [stop]
state=state+1
; bits=BitNot UInt8 lshift 1 BitAnd state 3
case mod state 4
[ [0 bits=0]
[1 bits=1]
[2 bits=3]
[3 bits=2]
]
bits=UInt8 bits
(pr steps IntForm bits 4 2)
PortOut adr BitNot bits
waituS speed
driveforward steps-1
end
be drivebackward steps
if steps==0 [stop]
state=state-1
; bits=abs BitNot UInt8 lshift 1 BitAnd state 3
case mod state 4
[ [0 bits=0]
[1 bits=1]
[2 bits=3]
[3 bits=2]
]
bits=UInt8 bits
(pr steps IntForm bits 4 2)
PortOut adr BitNot bits
waituS speed
drivebackward steps-1
end
end