code.py
1 # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """CircuitPython Essentials: PWM with Fixed Frequency example.""" 6 import time 7 import board 8 import pwmio 9 10 # LED setup for most CircuitPython boards: 11 led = pwmio.PWMOut(board.LED, frequency=5000, duty_cycle=0) 12 # LED setup for QT Py M0: 13 # led = pwmio.PWMOut(board.SCK, frequency=5000, duty_cycle=0) 14 15 while True: 16 for i in range(100): 17 # PWM LED up and down 18 if i < 50: 19 led.duty_cycle = int(i * 2 * 65535 / 100) # Up 20 else: 21 led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100) # Down 22 time.sleep(0.01)