Hello I have been working on an infinite While True loop for the main file in my python code. I am working on a Raspberry Pi and my goal is that whenever one of the GPIO Pins senses an input it will print out a string. However When I push a button it will keep printing it infinitely and the only way for it to stop is by hitting Ctrl-C. While it is printing the same string over and over no other button will change what happens. What am I doing wrong did I forget a step somewhere?
import RPi.GPIO as GPIO
import time
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN)
GPIO.setup(19, GPIO.IN)
GPIO.setup(13, GPIO.IN)
GPIO.setup(6, GPIO.IN)
input_A = GPIO.input(26)
input_B = GPIO.input(19)
input_C = GPIO.input(13)
input_D = GPIO.input(6)
while True:
if input_A == True:
print('A was pushed')
if input_B == True:
print('B was pushed')
if input_C == True:
print('C was pushed')
if input_D == True:
print('D was pushed')
sleep(1.5);
You need to keep updating your
input_*
variables inside your while loop