PWM_LED.py
 1  # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  import board
 7  import pwmio
 8  
 9  led = pwmio.PWMOut(board.D5, frequency=5000, duty_cycle=0)
10  
11  while True:
12      for i in range(100):
13          # PWM LED up and down
14          if i < 50:
15              led.duty_cycle = int(i * 2 * 65535 / 100)  # Up
16          else:
17              led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100)  # Down
18          time.sleep(0.01)