from machine import Pin, PWM # Import Pin and PWM to control the pins with Pulse Width Modulation
from utime import sleep_ms # Import sleep_ms to pause in milliseconds
# Create PWM objects for two servos on pins 21 and 4, with a 50Hz signal (standard for servos)
servo1 = PWM(Pin(21), freq=50)
servo2 = PWM(Pin(4), freq=50)
# Move both servos in opposite directions
for i in range(30, 114): # Loop from 30 to 113 (adjust to your servo's safe range)
servo1.duty(i + 30) # Servo 1 moves slowly forward
servo2.duty(114 - i) # Servo 2 moves in the opposite direction
print("Servo1 Duty:", i, "Servo2 Duty:", 114 - i) # Show the current servo positions
sleep_ms(15) # Short delay to make the movement smooth