Hey there,
I've been working on a project where 3 different push-buttons should trigger 3 different motors, and it's very close to working.
Right now, when I push the first button, it says "Button 1 Pressed" and the motor fires. However, when I push the second and third buttons, I get nothing. I'm guessing I've made a mistake with my while loops. Can anyone give any suggestions? Code below.
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(7, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(16, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
while True:
input_state_1 = GPIO.input(3)
if input_state_1 == False:
print('Button 1 Pressed')
GPIO.output(16, True)
time.sleep(2.6)
GPIO.output(16, False)
while True:
input_state_2 = GPIO.input(5)
if input_state_2 == False:
print('Button 2 Pressed')
GPIO.output(18, True)
time.sleep(2.6)
GPIO.output(18, False)
while True:
input_state_3 = GPIO.input(7)
if input_state_3 == False:
print('Button 3 Pressed')
GPIO.output(22, True)
time.sleep(2.6)
GPIO.output(22, False)