#! env/bin/python3 import RPi.GPIO as GPIO import time if __name__ == "__main__": # Setup for Hardware PB1_BCM = 4 # Green PB2_BCM = 27 # Yellow PB3_BCM = 13 # Blue GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # Use the internal pull-down. GPIO.setup(PB1_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(PB2_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) GPIO.setup(PB3_BCM, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Begin detected presses. i = 0 try: while True: # Green if GPIO.input(PB1_BCM): i += 1 print(f"Hi Gabby! Did you push the GREEN button? i = {i}") # Yellow if GPIO.input(PB2_BCM): i += 1 print(f"Hi Gabby! Did you push the YELLOW button? i = {i}") # Blue if GPIO.input(PB3_BCM): i += 1 print(f"Hi Gabby! Did you push the BLUE button? i = {i}") time.sleep(0.1) finally: GPIO.cleanup()