-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor-open-pins.py
More file actions
executable file
·64 lines (58 loc) · 1.22 KB
/
monitor-open-pins.py
File metadata and controls
executable file
·64 lines (58 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/env python3
import RPi.GPIO as GPIO
import time
from multiprocessing import Process
# List of GPIO pins to monitor
pinlist = [
3,
5,
7,
11,
13,
15,
19,
##27,
31,
33,
35,
37,
8,
10,
12,
##16,
18,
22,
##24,
##26,
##28,
32,
36,
38,
40
] # Example pins
def edge_detected(channel):
print(f"Edge detected on channel {channel}")
def monitor_pin(pin):
print(f"Starting monitoring for pin {pin}")
try:
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pin, GPIO.IN)
GPIO.add_event_detect(pin, GPIO.BOTH, callback=edge_detected)
# Keep the process running to monitor the pin
try:
while True:
time.sleep(1)
finally:
GPIO.cleanup(pin)
except Exception as e:
print(f"ERROR: Halting thread for {pin} due to {e}")
if __name__ == "__main__":
# Create and start a separate process for each pin to be monitored
processes = []
for pin in pinlist:
p = Process(target=monitor_pin, args=(pin,))
processes.append(p)
p.start()
# Join all processes to ensure they keep running
for process in processes:
process.join()