' ' stepper.bs2 ' ' Drive a 4 coil unipolar stepper motor using 4 Stamp pins ' Inefficient, but works if you have no L293 or ULN2003 ' ' Mark Crosbie 1/14/98 mark@mastincrosbie.com ' v1.0: Drives motor forwards ' v1.1: Added speedup/slowdown buttons ' ' Assumes: ' ' pin 5 pin 8 ' +-----| |-----+ ' % % ' 1 % % 3 ' % % ' +-----| |-----+ common - connected to 12V ' % % ' 2 % % 4 ' % % ' +-----| |-----+ ' pin 7 pin 10 ' ' These are defined as COIL1, COIL2, COIL3 and COIL4 ' ' Speedup: pin 12 ' Slowdown: pin 13 ' ' LCD: pin 11 ' symbolic constants for coil pins. COIL1 con 5 COIL2 con 7 COIL3 con 8 COIL4 con 10 SPEEDUP con 12 SLOWDOWN con 13 LCD con 11 N96N con 16468 LCDCLS con 1 LCDPREFIX con 254 ' These define which outputs get turned on to drive that coil. DRIV1 var word DRIV2 var word DRIV3 var word DRIV4 var word delay var word wrk1 var word wrk2 var word DRIV1 = dcd COIL1 DRIV2 = dcd COIL2 DRIV3 = dcd COIL3 DRIV4 = dcd COIL4 ' set output bits on all the driver lines dirs = (DRIV1 | DRIV2 | DRIV3 | DRIV4 | (ncd LCD)) delay = 20 wrk1 = 0 wrk2 = 0 ' set the LCD to the current delay serout LCD, N96N, [LCDPREFIX, LCDCLS] serout LCD, N96N, ["Delay = ", dec delay] top: button SPEEDUP, 1, 0, 20, wrk1, 0, checkslow if delay = 0 then checkslow delay = delay - 1 serout LCD, N96N, [LCDPREFIX, LCDCLS] serout LCD, N96N, ["Delay = ", dec delay] goto spin checkslow: button SLOWDOWN, 1, 0, 20, wrk2, 0, spin if delay = 200 then spin delay = delay + 1 serout LCD, N96N, [LCDPREFIX, LCDCLS] serout LCD, N96N, ["Delay = ", dec delay] spin: outs = DRIV1 | DRIV3 pause delay outs = DRIV1 | DRIV4 pause delay outs = DRIV2 | DRIV4 pause delay outs = DRIV2 | DRIV3 pause delay goto top