From 4638f342ba8e3793816c8b9030402c07edb3c267 Mon Sep 17 00:00:00 2001 From: Garth Johnson Date: Wed, 17 Apr 2024 19:42:36 -0700 Subject: [PATCH] added buttons 4 and 5 --- button.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/button.py b/button.py index 5f741ef..0cd3ba8 100644 --- a/button.py +++ b/button.py @@ -10,24 +10,33 @@ 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 = '' @@ -35,12 +44,16 @@ def reset(self): 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: @@ -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: @@ -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__':