from picozero import Servo, Button
from time import sleep
# Create Servo objects for each motor connected to the Raspberry Pi Pico
servo1 = Servo(15)
servo2 = Servo(14)
servo3 = Servo(13)
servo4 = Servo(12)
# Create Button objects for the buttons connected to GPIO pins
button1 = Button(0)
button2 = Button(1)
button3 = Button(2)
def control_servo(servo):
"""Rotate the specified servo and then rotate servo4 after a delay."""
servo.max() # Rotate the selected servo to max position
sleep(10) # Wait for 10 seconds
servo4.max() # Rotate servo4 to max position
sleep(5) # Wait for 5 seconds
servo4.min() # Return servo4 to its original (min) position
# Main loop to check button presses
while True:
if button1.is_pressed:
print("Plastic")
control_servo(servo1)
elif button2.is_pressed:
print("Metal")
control_servo(servo2)
elif button3.is_pressed:
print("Paper")
control_servo(servo3)
sleep(0.1) # Small delay to prevent excessive CPU usage