Adafruit_Learning_System_Gu.../CircuitPython_Essentials/PWM_Test_Script/code.py
2022-02-23 13:42:42 -05:00

20 lines
799 B
Python

# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""CircuitPython Essentials PWM pin identifying script"""
import board
import pwmio
for pin_name in dir(board):
pin = getattr(board, pin_name)
try:
p = pwmio.PWMOut(pin)
p.deinit()
print("PWM on:", pin_name) # Prints the valid, PWM-capable pins!
except ValueError: # This is the error returned when the pin is invalid.
print("No PWM on:", pin_name) # Prints the invalid pins.
except RuntimeError: # Timer conflict error.
print("Timers in use:", pin_name) # Prints the timer conflict pins.
except TypeError: # Error returned when checking a non-pin object in dir(board).
pass # Passes over non-pin objects in dir(board).