-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.py
More file actions
57 lines (47 loc) · 1.37 KB
/
button.py
File metadata and controls
57 lines (47 loc) · 1.37 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
import gpiozero as gz
import sys
from functools import partial
class Button:
def __init__(self, pinSwitch, pinLED, ID, player):
self.lock = False
self.pinSwitch = pinSwitch
self.pinLED = pinLED
self.ID = ID
self.player = player
self.button = gz.Button(self.pinSwitch, pull_up=False)
self.led = gz.LED(pinLED, active_high=False)
self.led.off()
self.button.when_pressed = self.down
self.button.when_released = self.up
def down(self):
self.led.on()
if not self.lock:
try:
if self.ID == 0:
self.player.nextPlaylist()
if self.ID == 1:
self.player.playPause()
if self.ID == 2:
self.player.prev()
if self.ID == 3:
self.player.next()
except:
print("not ready yet", sys.exc_info()[0])
pass
def up(self, args):
self.led.off()
def on(self):
self.led.on()
def off(self):
self.led.off()
def lockUnlock(self):
self.lock = not self.lock
if __name__ == "__main__":
import time
def startSignal(buttons):
for b in buttons:
b.on()
time.sleep(0.2)
for b in buttons:
b.off()
time.sleep(0.2)