this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: add broken forward reverse code

+55
+55
code.py
··· 1 + import board 2 + import time 3 + import digitalio 4 + 5 + # Define pins for stepper motors 6 + motor1_step = digitalio.DigitalInOut(board.GP10) 7 + motor1_step.direction = digitalio.Direction.OUTPUT 8 + motor1_dir = digitalio.DigitalInOut(board.GP9) 9 + motor1_dir.direction = digitalio.Direction.OUTPUT 10 + motor2_step = digitalio.DigitalInOut(board.GP8) 11 + motor2_step.direction = digitalio.Direction.OUTPUT 12 + motor2_dir = digitalio.DigitalInOut(board.GP7) 13 + motor2_dir.direction = digitalio.Direction.OUTPUT 14 + enable = digitalio.DigitalInOut(board.GP1) 15 + enable.direction = digitalio.Direction.OUTPUT 16 + 17 + # Enable motors 18 + enable.value = False 19 + print("Motors enabled") 20 + 21 + # Function to step motor 22 + def step(step_pin): 23 + step_pin.value = True 24 + time.sleep(0.000001) # 1 microsecond 25 + step_pin.value = False 26 + time.sleep(0.000001) # 1 microsecond 27 + 28 + while True: 29 + # Set direction forward 30 + motor1_dir.value = True 31 + motor2_dir.value = True 32 + print("Moving motors forward...") 33 + 34 + # Run motors forward for 1 second 35 + start = time.time() 36 + while time.time() - start < 1: 37 + step(motor1_step) 38 + step(motor2_step) 39 + time.sleep(0.001) 40 + 41 + print("Forward movement complete") 42 + 43 + # Set direction reverse 44 + motor1_dir.value = False 45 + motor2_dir.value = False 46 + print("Moving motors in reverse...") 47 + 48 + # Run motors reverse for 1 second 49 + start = time.time() 50 + while time.time() - start < 1: 51 + step(motor1_step) 52 + step(motor2_step) 53 + time.sleep(0.001) 54 + 55 + print("Reverse movement complete")