-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathpin_state.py
More file actions
24 lines (21 loc) · 761 Bytes
/
pin_state.py
File metadata and controls
24 lines (21 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# pin_state.py -- look at state of all pins in `board`
# 6 Jul 2022 - @todbot / Tod Kurt
#
import time, board, microcontroller, digitalio
def get_pin_states():
pin_states = {}
for name in sorted(dir(board)):
maybe_pin = getattr(board, name)
if isinstance(maybe_pin, microcontroller.Pin):
try:
test_pin = digitalio.DigitalInOut( maybe_pin )
test_pin.direction = digitalio.Direction.INPUT
pin_states[ name ] = test_pin.value
except:
pin_states[ name ] = None # in use
return pin_states
while True:
pin_states = get_pin_states()
for name,value in pin_states.items():
print(f"{name:<15} = {value}")
time.sleep(1)