' Control Software for Unlocking a Combination Lock ' Using a Stepper Motor ' Written by Vince Long ' May 2006 ' This is freeware. There is no warranty or support. ' Use at your own risk. ' * * * * * * * * * * * * * * * * * * * * * * * ' Setup the program ' You may need to change the value for Delay to suit your CPU speed. ' It was tested on a 486-33. ' * * * * * * * * * * * * * * * * * * * * * * * CLS OUT 888, 0 Delay = 1000 x = 0: y = 9 ' * * * * * * * * * * * * * * * * * * * * * * * ' Read the step values into an array. ' These are the values that will be sent to the ' parallel port. The will cause the motor coils ' to be turned on in the proper sequence. I am ' using the interleaving approach for greater ' accuracy. ' * * * * * * * * * * * * * * * * * * * * * * * FOR I = 1 TO 8 READ OutVal(I) NEXT I Start: CLS INPUT "What is the first number"; F INPUT "What is the second number"; S INPUT "What is the third number"; T INPUT "What is the starting number"; StartNum ' * * * * * * * * * * * * * * * * * * * * * * * ' This section sets the number of ' cycles that will be sent to the motor ' to comlete a move. The values show ' control the distance. For my motor it took ' about 11 cycles to move 1/40th of a turn, ' which is one number on the dial. ' * * * * * * * * * * * * * * * * * * * * * * * GetToZero = INT(StartNum * 11.4) AroundTwice = 905 GetToFirstNum = INT((40 - F) * 11.2) GetToSecondNum = INT((40 - F + S) * 11.4) GetToThirdNum = INT((40 - T + S) * 11.3) PRINT "Press a key to start" DO I$ = INKEY$ LOOP WHILE I$ = "" ' * * * * * * * * * * * * * * * * * * * * * * * ' This moves the lock to zero. ' Note that I stop the process after ' each move to very the dial position. ' You might want to remove these ' pauses. ' * * * * * * * * * * * * * * * * * * * * * * * Pulses = GetToZero PRINT "Sending "; GetToZero; " pulses to get to zero" GOSUB ClockWise GOSUB PressAny Pulses = AroundTwice PRINT "Sending "; AroundTwice; " pulses to go around twice" GOSUB ClockWise GOSUB PressAny Pulses = GetToFirstNum PRINT "Sending "; GetToFirstNum; " pulses to get to "; F GOSUB ClockWise GOSUB PressAny Pulses = GetToSecondNum PRINT "Sending "; GetToSecondNum; " pulses in reverse to go past "; F; " and get to "; S GOSUB CounterClockWise GOSUB PressAny Pulses = GetToThirdNum PRINT "Sending "; GetToThirdNum; " pulses to go to "; T GOSUB ClockWise BEEP PRINT PRINT "Done!" PRINT "Try to open the lock" PRINT GOSUB PressAny GOTO Start ' * * * * * * * * * * * * * * * * * * * * * * * ' Subrouting to Pause ' * * * * * * * * * * * * * * * * * * * * * * * PressAny: PRINT "Press a key" DO I$ = INKEY$ LOOP WHILE I$ = "" RETURN ' * * * * * * * * * * * * * * * * * * * * * * * ' Rotates the stepper motor clockwise ' * * * * * * * * * * * * * * * * * * * * * * * ClockWise: FOR I = 1 TO Pulses x = x + 1 IF x > 8 THEN x = 0 OUT 888, OutVal(x) FOR d = 1 TO Delay: NEXT d NEXT I OUT 888, 0 RETURN ' * * * * * * * * * * * * * * * * * * * * * * * ' Rotates the stepper motor counter-clockwise ' * * * * * * * * * * * * * * * * * * * * * * * CounterClockWise: FOR I = 1 TO Pulses y = y - 1 IF y < 1 THEN y = 9 OUT 888, OutVal(y) FOR d = 1 TO Delay: NEXT d NEXT I OUT 888, 0 RETURN ' * * * * * * * * * * * * * * * * * * * * * * * ' The values that will control which coils are activated. ' * * * * * * * * * * * * * * * * * * * * * * * DATA 1,3,2,6,4,12,8,9