-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch_test.py
More file actions
executable file
·45 lines (31 loc) · 1001 Bytes
/
switch_test.py
File metadata and controls
executable file
·45 lines (31 loc) · 1001 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/env python3
import RPi.GPIO as GPIO
import time
from datetime import datetime
# Setup the GPIO pin numbers
VOL_UP = 27
VOL_DOWN = 4
POWER = 21
switches = [VOL_UP, VOL_DOWN, POWER]
GPIO.setmode(GPIO.BCM)
GPIO.setup(POWER, GPIO.IN)
for switch in switches:
print(switch)
GPIO.setup(switch, GPIO.IN)
def power_callback(channel):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print(f"{current_time}: Power Pressed")
def vol_up_callback(channel):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print(f"{current_time}: Vol Up Pressed")
def vol_down_callback(channel):
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print(f"{current_time}: Vol Down Pressed")
GPIO.add_event_detect(POWER, GPIO.RISING, callback=power_callback)
GPIO.add_event_detect(VOL_UP, GPIO.RISING, callback=vol_up_callback)
GPIO.add_event_detect(VOL_DOWN, GPIO.RISING, callback=vol_down_callback)
while(True):
time.sleep(0.1)