DECLARE SUB showbits (j%) DECLARE SUB moveboth (a!, B!) CONST port = &H378 CONST up$ = "H", dn$ = "P", le$ = "K", ri$ = "M" 'cursor keys DIM SHARED hidrive(7) AS INTEGER, lodrive(7) AS INTEGER ' bit patterns for motor 1, motor 2 using bits 0-3 and 4-7 FOR i = 0 TO 7 READ lodrive(i) hidrive(i) = lodrive(i) * 16 NEXT DATA 1, 5, 4, 6, 2, 10, 8, 9 ' N, NE, E, SE, S, SW, W, NW PLAY "t255l64ms" 'sets fastest music speed if PLAY delay is used SCREEN 9 'graphics 640 by 350 WINDOW (-5, -5)-(15, 10) 'scaled as x = -5 to 15, y = -5 to 10 ' INPUT "speed1, speed2 - between +/- 1 ", speed1, speed2 here1 = 1 'start position is NE for motor 1 here2 = 1 'also for motor 2 CLS PRINT "Press cursor key to move, q to end" moveboth here1, here2 DO a$ = INKEY$ IF a$ <> "" THEN SELECT CASE MID$(a$, 2) CASE up$: here1 = here1 + 1: here2 = here2 + 1 CASE dn$: here1 = here1 - 1: here2 = here2 - 1 CASE le$: here1 = here1 - 1: here2 = here2 + 1 CASE ri$: here1 = here1 + 1: here2 = here2 - 1 END SELECT moveboth here1, here2 END IF LOOP UNTIL a$ = "q" 'keep going until q key is pressed OUT port, 0 'switch off all windings SUB moveboth (a, B) i1% = INT(a) AND 7 i2% = INT(B) AND 7 j% = lodrive(i1%) + hidrive(i2%) OUT port, j% showbits j% 'PLAY "n60" 'If you remove the "remark" quote to "wake up" this line 'it will introduce a delay between steps '(The graphics should be enough delay, though) END SUB DEFINT I-N SUB showbits (j%) DIM jbit(7) 'to remember bits for drawing motors k = j% FOR i = 0 TO 7 jbit(i) = k AND 1 'pick out right-hand bit of k IF jbit(i) = 1 THEN LINE (2 * i - 3, 2)-(2 * i - 2, 3), 15, BF 'bright white, box-fill ELSE LINE (2 * i - 3, 2)-(2 * i - 2, 3), 0, BF 'black, box-fill LINE (2 * i - 3, 2)-(2 * i - 2, 3), 12, B 'red, box-empty END IF k = k \ 2 'move bits of k one-to-the-right to get next bit NEXT 'Now draw motors LINE (-1, -1)-(1, 1), 0, BF 'black square to rub out motor 1 CIRCLE (0, 0), 1, 12 'red circle for motor 1 LINE (0, 0)-(jbit(2) - jbit(3), jbit(0) - jbit(1)), 15 'radius line LINE (7, -1)-(9, 1), 0, BF 'black square to rub out motor 2 CIRCLE (8, 0), 1, 10 'green circle for motor 2 LINE (8, 0)-(8 + jbit(6) - jbit(7), jbit(4) - jbit(5)), 15 'radius line END SUB