TrainCircuit/Relays/script.py

51 lines
699 B
Python
Raw Normal View History

2020-02-22 18:05:01 +00:00
import RPi.GPIO as GPIO
PUSH = [
21, #1
20, #2
16, #3
26 #4
]
RELAYS = [
2020-02-22 18:27:27 +00:00
[], #1
[14,2], #2
[15, 3], #3
[18, 4] #4
2020-02-22 18:05:01 +00:00
]
# 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)
2020-02-22 18:23:12 +00:00
# Relays
for i in RELAYS:
for j in i:
print("Init relay: "+str(j))
GPIO.setup(j, GPIO.OUT)
GPIO.output(j, True)
2020-02-22 18:05:01 +00:00
# Infinite loop
while True:
for num in range(0, len(PUSH)):
if GPIO.input(PUSH[num]) == False:
print("Button " + str(num) + " pressed")
2020-02-22 18:23:12 +00:00
for curr in range(0, len(PUSH)):
for id_relay in RELAYS[curr]:
GPIO.output(id_relay, curr != num) # Inverted condition