File tree Expand file tree Collapse file tree
CircuitPython_Templates/audio_find_pins Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ CircuitPython Audio-capable pin identifying script
3+ """
4+ import board
5+ from microcontroller import Pin
6+ try :
7+ from audioio import AudioOut
8+ except ImportError :
9+ from audiopwmio import PWMAudioOut as AudioOut
10+
11+
12+ def is_audio (audio_pin_name ):
13+ try :
14+ p = AudioOut (audio_pin_name )
15+ p .deinit ()
16+ return True
17+ except ValueError :
18+ return False
19+ except RuntimeError :
20+ return False
21+
22+
23+ def get_unique_pins ():
24+ exclude = [
25+ getattr (board , p )
26+ for p in [
27+ # This is not an exhaustive list of unexposed pins. Your results
28+ # may include other pins that you cannot easily connect to.
29+ "NEOPIXEL" ,
30+ "DOTSTAR_CLOCK" ,
31+ "DOTSTAR_DATA" ,
32+ "APA102_SCK" ,
33+ "APA102_MOSI" ,
34+ "L" ,
35+ "SWITCH" ,
36+ "BUTTON" ,
37+ ]
38+ if p in dir (board )
39+ ]
40+ pins = [
41+ pin
42+ for pin in [getattr (board , p ) for p in dir (board )]
43+ if isinstance (pin , Pin ) and pin not in exclude
44+ ]
45+ unique = []
46+ for p in pins :
47+ if p not in unique :
48+ unique .append (p )
49+ return unique
50+
51+
52+ for audio_pin in get_unique_pins ():
53+ if is_audio (audio_pin ):
54+ print ("Audio pin:" , audio_pin )
You can’t perform that action at this time.
0 commit comments