Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added buttons 4 and 5 #10

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions button.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,50 @@ def __init__(self):

#Setup pins and board
gpio.setmode(gpio.BCM)

#Pin 17 is Team 1
gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_DOWN)
#Pin 22 is Team 2
gpio.setup(22, gpio.IN, pull_up_down=gpio.PUD_DOWN)
#Pin 4 is Team 3
gpio.setup(4, gpio.IN, pull_up_down=gpio.PUD_DOWN)
#Pin 17 is Team 1
gpio.setup(17, gpio.IN, pull_up_down=gpio.PUD_DOWN)
#Pin 27 is Team 4
gpio.setup(27, gpio.IN, pull_up_down=gpio.PUD_DOWN)
#Pin 5 is Team 5
gpio.setup(5, gpio.IN, pull_up_down=gpio.PUD_DOWN)
#GPIO Needs to be setup between 3.3v and pins above

#Put pins in variables
self.center_button = 22
self.right_button = 4
self.left_button = 17
self.fourth_button = 27
self.fifth_button = 5

self.first = ''

self.center_press = 0
self.right_press = 0
self.left_press = 0
self.fourth_press = 0
self.fifth_press = 0

def reset(self):
self.first = ''

self.center_press = 0
self.right_press = 0
self.left_press = 0
self.fourth_press = 0
self.fifth_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
self.fourth_press = 0
self.fifth_press = 0

#Check for button presses
while True:
Expand All @@ -54,6 +67,10 @@ def check(self):
center_input = gpio.input(self.center_button)
left_input = gpio.input(self.left_button)
right_input = gpio.input(self.right_button)
fourth_input = gpio.input(self.fourth_button)
fifth_input = gpio.input(self.fifth_button)

#Center buttons stuff
if center_input == gpio.HIGH:
if self.center_press > 0:
if self.DEBUG:
Expand Down Expand Up @@ -89,6 +106,30 @@ def check(self):
pass
self.left_press += 1

#Fourth button stuff
if fourth_input == gpio.HIGH:
if self.fourth_press > 0:
if self.DEBUG:
print('ADMIN: Console button 4 has been pressed')
self.first = 3

else:
if self.DEBUG:
pass
self.fourth_press += 1

#Fifth button stuff
if fifth_input == gpio.HIGH:
if self.fifth_press > 0:
if self.DEBUG:
print('ADMIN: Console button 5 has been pressed')
self.first = 4

else:
if self.DEBUG:
pass
self.fifth_press += 1

return self.first

if __name__ == '__main__':
Expand Down
Loading