from machine import Pin,PWM
import utime
MID = 1500000
MIN = 1000000
MAX = 2000000
pwm = PWM(Pin(0)) #GPIO Number
pwm.freq(50)
pwm.duty_ns(MID)
while True:
pwm.duty_ns(MIN)
utime.sleep(1) #Sleep Time In Seconds
pwm.duty_ns(MID)
utime.sleep(1) #Sleep Time In Seconds
pwm.duty_ns(MAX)
utime.sleep(1) #Sleep Time In Seconds
from machine import Pin, PWM
from time import sleep
servoPin = PWM(Pin(0)) #GPIO Pin Number
servoPin.freq(50)
def servo(degrees):
# Limit Degrees Between 0 And 180
if degrees > 180: degrees=180
if degrees < 0: degrees=0
# Set Max And Min Duty
maxDuty=9000
minDuty=1000
# New Duty Is Between Min And Max Duty In Proportion To It's Value
newDuty=minDuty+(maxDuty-minDuty)*(degrees/180)
# Servo PWM Value Is Set
servoPin.duty_u16(int(newDuty))
while True:
# Start Increasing Loop
for degree in range(0,180,1):
servo(degree)
sleep(0.001)
print("increasing -- "+str(degree))
# Start Decreasing Loop
for degree in range(180, 0, -1):
servo(degree)
sleep(0.001)
print("decreasing -- "+str(degree))