from machine import Pin
import utime
dir_pins = [14,2]
step_pins = [15,3]
pin_state = Pin.OUT
for pin in dir_pins:
dir_pin = Pin(pin, pin_state)
dir_pin.off()
for pin in step_pins:
step_pin = Pin(pin, pin_state)
step_pin.off()
# # Define pins for a motor
# x_dir_pin = Pin(14, Pin.OUT)
# x_step_pin = Pin(15, Pin.OUT)
# # Define pins for b motor
# y_dir_pin = Pin(6, Pin.OUT)
# y_step_pin = Pin(7, Pin.OUT)
# # Define pins for c motor
# z_dir_pin = Pin(2, Pin.OUT)
# z_step_pin = Pin(3, Pin.OUT)
x = y = z = 0
mm_per_step = 0.314
max_x = 300
max_y = 100
max_z = 20
# x_dir_pin.off()
# y_dir_pin.off()
# z_dir_pin.off()
# x_step_pin.off()
# y_step_pin.off()
# z_step_pin.off()
def rotate_initial(steps, direction, delay):
dir_pin.value(direction)
for _ in range(steps):
step_pin.on()
utime.sleep_ms(delay)
step_pin.off()
utime.sleep_ms(delay)
def rotate_x(steps, direction, delay):
dir_pin.value(direction)
for _ in range(steps):
step_pin.on()
utime.sleep_ms(delay)
step_pin.off()
utime.sleep_ms(delay)
def rotate_z(steps, direction, delay):
dir_pin.value(direction)
for _ in range(steps):
step_pin.on()
utime.sleep_ms(delay)
step_pin.off()
utime.sleep_ms(delay)
rotate_initial(2,1,0)
x = float(input("x = "))
z = float(input("z = "))
move_x = x / mm_per_step
move_y = y / mm_per_step
move_z = z / mm_per_step
print(move_x)
print(move_z)
# Move 200 steps (one rotation) CW over one second
rotate_x(move_x, 1, 5)
rotate_z(move_z, 1, 5)
utime.sleep_ms(500) # Wait half a second
# # Move 200 steps (one rotation) CCW over 400 milliseconds
# rotate_steppers(200, 0, 2)
# utime.sleep_ms(1000) # Wait another second
Loading
pi-pico-w
pi-pico-w