What I am trying to do is enter a number into the function move and get movement that is up if the argument is greater than the previous argument or move down if the argument is lower than the previous argument. But as shown in the commented code if starting after moving from .5 to .125 it should move down the difference of .375. What I am getting is the movement always going up and and it's not modifying the variable 'oldSteps'. Can I get some fresh eyes and help me figure out what I'm doing wrong?
def move(n):
numberEntered = float(n)
stepPerRev = 400
TPI = 4
steps = int(( float( stepPerRev) * float( TPI ) ) * numberEntered)
oldSteps = 0 # place holder for oldSteps
if steps > oldSteps: #turn ccw
for i in range(steps - oldSteps):
print i # turning code
oldSteps -= steps
print 'did %s steps up' % int(steps - oldSteps)
if steps < oldSteps: # turn cw
for i in range( oldSteps - steps ):
print i # turning code
oldSteps -= steps
print 'did %s steps down' % int(oldSteps - steps)
return 0
move(.5) # move up 1/2 of inch
move(.125) # move down from 1/2 to 1/8 of inch ( move 3/8 of inch)