# Import Pin and PWM modules to control pins and use Pulse Width Modulation
from machine import Pin, PWM
# Import time functions to add delays (seconds and milliseconds)
from utime import sleep, sleep_ms
# Create a PWM signal on pin 21 with a frequency of 50Hz (for servo motor)
servo1 = PWM(Pin(21), freq=50)
# Repeat the following 100 times
for i in range(100):
# Change the PWM duty cycle to 'i' (this moves the servo position)
servo1.duty(i)
# Print the current duty value to the console for observation
print(i)
# Wait for 15 milliseconds to allow the servo to move smoothly
sleep_ms(15)