SETZEROUP: ;start of stepping
do
gosub GKP ; keypad routine omitted for clarity
if key_value = 10 then goto mini ; drive stepper forward
if key_value = 12 then goto mini1 ; drive stpper backwards
if key_value = 0 then goto SLACK ; confirm in zero start position and to start main run
loop
mini:
let dirsC = %11110000 ;defines output pins for stepper
let pinsB = %00101011 ;an easier way for a button press on keypad
serout lcdpin,baud,(255,%011) ; lights indicating LED
do
let pinsC = %10100000 ;step sequence
pauseus 200 ;pause time between steps, have found this is the lowest I can go
let pinsC = %10010000
pauseus 200
let pinsC = %01010000
pauseus 200
let pinsC = %01100000
pauseus 200
loop until COL2 = 1 ; if button pressed on keypad it stops run
serout lcdpin,baud,(255,%001) ; turns LED off and illuminates another
goto SETZEROUP
mini1: ;same as above but in reverse
let dirsC = %11110000
let pinsB = %00101011
serout lcdpin,baud,(255,%011)
do
let pinsC = %01100000
pauseus 200
let pinsC = %01010000
pauseus 200
let pinsC = %10010000
pauseus 200
let pinsC = %10100000
pauseus 200
loop until COL2 = 1
serout lcdpin,baud,(255,%001)
goto SETZEROUP
SLACK: ;short sequence of steps to take slack out of rail drive train
let dirsC = %11110000
for b12 = 1 to 2
let pinsC = %01100000
pauseus 200
let pinsC = %01010000
pauseus 200
let pinsC = %10010000
pauseus 200
let pinsC = %10100000
pause 10
next b12
RUNMACRO:
let w5 = w5 * 1000 ;adjustable pause time between shots and steps
let w21 = w20 * 400 / w22 ;calculation to get number of steps to do per stack
let w26 = w22 ;allows 2 variables to be used as one is used as countdown
serout lcdpin,baud,(254,1)
pause 30
serout lcdpin,baud,(254,128,"MACRO RAIL RUNNING")
serout lcdpin,baud,(254,148,"STACK SET = ",254,160,#w22)
serout lcdpin,baud,(254,212,"STEPS LEFT = ",254,225,#w26," ")
let pinsB = %00101011
steprun: ;this part essentially sets camera mirror lock up
serout lcdpin,baud,(255,%101)
high CAMERA
pause 500
low CAMERA
pause RAILPAUSE
high CAMERA : high FLASH
pause 500
low CAMERA : low FLASH
serout lcdpin,baud,(255,%011)
let dirsC = %11110000
steprun2: ; this is westaus55's code to do halfstepping
for w27 = 1 to w21 ;w21 is the number of steps to do
b2 = b2 + 1
b2 = b2 & %00000111
lookup b2,(%00100000,%01100000,%01000000,%01010000,%00010000,%10000000,%100000000,%10100000),b3
pinsC = b3
inc w18 ;allows w18 to be used as a counter later in code
inc w25 ;same again, used as a counter
if w27 = w21 then goto steprun3
next w27
goto steprun2
steprun3:
dec w26
serout lcdpin,baud,(254,225,#w26," ")
if w26 = 0 then goto returns
if COL1 = 1 then goto abort
goto steprun
abort: ;if keypress is activated the run is aborted and using w18, it returns to zero
low READY_LED
serout lcdpin,baud,(255,%010)
serout lcdpin,baud,(254,1)
pause 30
serout lcdpin,baud,(254,128," OPERATION ABORTED")
serout lcdpin,baud,(254,192," RETURNING TO ZERO")
serout lcdpin,baud,(254,148," POSITION")
pause 250
let dirsC = %11110000
let w18 = w18 / 8
do
let pinsC = %10100000
pauseus 200
let pinsC = %10010000
pauseus 200
let pinsC = %01010000
pauseus 200
let pinsC = %01100000
pauseus 200
dec w18
loop until w18 = 0
pause 30
serout lcdpin,baud,(255,%000)
pause 30
goto INIT
returns: ;when reaches end of run uses w25 to count back to zero
low READY_LED
serout lcdpin,baud,(255,%011)
serout lcdpin,baud,(254,1)
pause 30
serout lcdpin,baud,(254,128," RETURNING TO ZERO")
serout lcdpin,baud,(254,192," POSITION")
pause 250
let dirsC = %11110000
let w25 = w25 / 8
do
let pinsC = %10100000
pauseus 200
let pinsC = %10010000
pauseus 200
let pinsC = %01010000
pauseus 200
let pinsC = %01100000
pauseus 200
dec w25
loop until w25 = 0
pause 30
serout lcdpin,baud,(255,%000)
pause 30
goto INIT ; run complete and goes back to start