import RPi.GPIO as GPIO PUSH = [ 21, #1 20, #2 16, #3 26 #4 ] RELAYS = [ [14], #1 [], #2 [], #3 [] #4 ] # Initialize GPIO.setmode(GPIO.BCM) # Push buttons for i in PUSH: print("Init push button: " + str(i)) GPIO.setup(i, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Relays for i in RELAYS: for j in i: print("Init relay: "+str(j)) GPIO.setup(j, GPIO.OUT) GPIO.output(j, True) # Infinite loop while True: for num in range(0, len(PUSH)): if GPIO.input(PUSH[num]) == False: print("Button " + str(num) + " pressed") for curr in range(0, len(PUSH)): for id_relay in RELAYS[curr]: GPIO.output(id_relay, curr != num) # Inverted condition