from machine import Pin, PWM
import utime
# Set the constant for the PWM limit value
PWM_MAX = (2 ** 16) - 1
# Set the PWM frequency to 100Hz
PWM_FREQUENCY = 100
# Set the standard step size for the PWM when
# incrementing (or decrementing) the PWM output
# during 'on' or 'off' movements
PWM_STEP = 650
# Set GPIO Pin 2 as the PWM output pin, at the
# standard frequency and with a duty cycle of 0
pwm_pin = PWM(Pin(2))
pwm_pin.duty_u16(0)
pwm_pin.freq(PWM_FREQUENCY)
# Read the voltage from the ADC, convert to
# a temperature in degrees Celsius, print that
# temperature to the console, and repeat
# every second
while True:
# Turn the LED slowly on
for duty in range(0, PWM_MAX, PWM_STEP):
print(f"duty on: {duty}")
pwm_pin.duty_u16(duty)
utime.sleep_ms(10)
# Turn the LED slowly off
for duty in range(PWM_MAX, 0, -PWM_STEP):
print(f"duty off: {duty}")
pwm_pin.duty_u16(duty)
utime.sleep_ms(10)