How do I cycle through an array in reverse order?
Ok, I ditched the bi-polar and I'm using a pic and mosfets to drive a uni motor. No translator.
I can spin the motor both ways with the following code but there has to be a more elegant way....I'm thinking I could cut the code in half.
Here's a clip of the program:
'Array vars
stepccw VAR BYTE(4) 'coils
stepcw var byte(4)
'Load Arrays
stepcw[0] = %10100000
stepcw[1] = %01100000
stepcw[2] = %01010000
stepcw[3] = %10010000
stepccw[0] = %10010000
stepccw[1] = %01010000
stepccw[2] = %01100000
stepccw[3] = %10100000
CW:
steps = 0
for delaytime = 1 to 27
steps = steps + 1
portb = stepccw[steps //4]
pause 10
next
pause 1000
steps = 0
CCW:
for delaytime = 27 to 1 step -1
steps = steps + 1
portb = stepcw[steps //4]
pause 10
next
pause 1000
goto cw




Bookmarks