This repository was archived by the owner on May 4, 2021. It is now read-only.
forked from adambeagle/JeoparPy
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbutton.py
More file actions
95 lines (77 loc) · 2.47 KB
/
button.py
File metadata and controls
95 lines (77 loc) · 2.47 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#Poll Raspberry Pi Buttons and control LEDS
#By Tyler Spadgenske
import RPi.GPIO as gpio
import time
class Poll():
def __init__(self):
self.DEBUG = True
#Setup pins and board
gpio.setmode(gpio.BCM)
gpio.setup(22, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(4, gpio.IN, pull_up_down=gpio.PUD_UP)
gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_UP)
#Put pins in variables
self.center_button = 22
self.right_button = 4
self.left_button = 17
self.first = ''
self.center_press = 0
self.right_press = 0
self.left_press = 0
def reset(self):
self.first = ''
self.center_press = 0
self.right_press = 0
self.left_press = 0
def poll(self): #Returns first button pressed
#Variables for press count (one for each button)
self.center_press = 0
self.right_press = 0
self.left_press = 0
#Check for button presses
while True:
self.first = self.check()
if self.first != '':
break
time.sleep(.5)
return self.first
def check(self):
center_input = gpio.input(self.center_button)
left_input = gpio.input(self.left_button)
right_input = gpio.input(self.right_button)
if center_input == True:
if self.center_press > 0:
if self.DEBUG:
print('ADMIN: Console button 2 has been pressed')
self.first = 1
else:
if self.DEBUG:
pass
self.center_press += 1
#Right buttons stuff
if right_input == True:
if self.right_press > 0:
if self.DEBUG:
print('ADMIN: Console button 3 has been pressed')
self.first = 2
else:
if self.DEBUG:
pass
self.right_press += 1
#Left button stuff
if left_input == True:
if self.left_press > 0:
if self.DEBUG:
print('ADMIN: Console button 1 has been pressed')
self.first = 0
else:
if self.DEBUG:
pass
self.left_press += 1
return self.first
if __name__ == '__main__':
test = Poll()
while True:
test.first = ''
winner = test.poll()
print winner