Complete the code to read the state of a GPIO pin.
import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN) state = GPIO.[1](17) print(state)
The GPIO.input() function reads the digital state of a pin set as input.
Complete the code to check if the button connected to pin 22 is pressed (assuming active low).
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP) if GPIO.[1](22) == GPIO.LOW: print("Button pressed")
Use GPIO.input() to read the pin state and compare it to GPIO.LOW for active low buttons.
Fix the error in the code to correctly read a pin state.
GPIO.setup(5, GPIO.IN) pin_state = GPIO.[1](5) if pin_state == 1: print("Pin is HIGH")
The correct function to read a pin is GPIO.input(). Other options cause errors.
Fill both blanks to create a dictionary of pin states for pins 10 and 11.
pins = [10, 11] states = {pin: GPIO.[1](pin) for pin in pins if GPIO.[2](pin) == GPIO.HIGH}
Use GPIO.input() to read pin states. Both blanks require the same function.
Fill all three blanks to create a dictionary of pin states for pins 7, 8, and 9 where the state is HIGH.
pins = [7, 8, 9] high_pins = {pin: GPIO.[1](pin) for pin in pins if GPIO.[2](pin) == GPIO.[3]
Use GPIO.input() to read pins and compare to GPIO.HIGH to filter pins that are on.