Question: The code is supposed to detect when a GPIO pin is pulled high by a switch. Can some one pease explain the line: while inputvalue1==1:

The code is supposed to detect when a GPIO pin is pulled high by a switch.
Can some one pease explain the line: while inputvalue1==1:
How does that While loop avoid the printed message from continuously printing? (I get the while true: loop that continuously runs but how does that while inside work?) Please explain thoroughly. Thanks!
import RPi.GPIO as GPIO import time import sys GPIO.setmode (GPIO.BCM) pin_1 = 17 # BCM17 pin_2= 27 pin_3= 22 pin_4= 5 GPIO.setup(pin_1, GPIO.IN) GPIO.setup(pin_2, GPIO.IN) GPIO.setup(pin_3, GPIO.IN) GPIO.setup(pin_4, GPIO.IN) try: while True: inputvalue1 inputvalue2 inputvalue3 inputvalue4 = = GPIO.input(17) # GPIOs that swicthes are connected to GPIO.input(27) = GPIO.input (22) GPIO.input(5) = if inputvalue1==1: # active high swicth print("GPIO number: ",pin_1," is pressed") while inputvalue1==1: # so that message doesnt print continuosly inputvalue1=GPIO.input(pin_1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
