linted clean, tested 293D and 2803A runs smooth, python3 compatible
-import board
import time
-from adafruit_motor import stepper
+import board
import digitalio
enable_pin = digitalio.DigitalInOut(board.D18)
@@ -15,8 +14,11 @@ coil_A_2_pin.direction = digitalio.Direction.OUTPUT
coil_B_1_pin.direction = digitalio.Direction.OUTPUT
coil_B_2_pin.direction = digitalio.Direction.OUTPUT
+enable_pin.value = True
+
def forward(delay, steps):
- for i in range(0, steps):
+ i = 0
+ while i in range(0, steps):
setStep(1, 0, 1, 0)
time.sleep(delay)
setStep(0, 1, 1, 0)
@@ -25,9 +27,11 @@ def forward(delay, steps):
time.sleep(delay)
setStep(1, 0, 0, 1)
time.sleep(delay)
+ i += 1
def backwards(delay, steps):
- for i in range(0, steps):
+ i = 0
+ while i in range(0, steps):
setStep(1, 0, 0, 1)
time.sleep(delay)
setStep(0, 1, 0, 1)
@@ -36,6 +40,7 @@ def backwards(delay, steps):
time.sleep(delay)
setStep(1, 0, 1, 0)
time.sleep(delay)
+ i += 1
def setStep(w1, w2, w3, w4):
coil_A_1_pin.value = w1
@@ -44,8 +49,8 @@ def setStep(w1, w2, w3, w4):
coil_B_2_pin.value = w4
while True:
- delay = input("Delay between steps (milliseconds)?")
- steps = input("How many steps forward? ")
- forward(int(delay) / 1000.0, int(steps))
- steps = input("How many steps backwards? ")
- backwards(int(delay) / 1000.0, int(steps))
+ user_delay = input("Delay between steps (milliseconds)?")
+ user_steps = input("How many steps forward? ")
+ forward(int(user_delay) / 1000.0, int(user_steps))
+ user_steps = input("How many steps backwards? ")
+ backwards(int(user_delay) / 1000.0, int(user_steps))
