Bird
0
0

What will be the output of this code snippet if the button connected to pin 22 is pressed (assuming pressed means HIGH)?

medium📝 Predict Output Q13 of 15
Raspberry Pi - GPIO Basics with Python
What will be the output of this code snippet if the button connected to pin 22 is pressed (assuming pressed means HIGH)?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN)
state = GPIO.input(22)
print(state)
ATrue
B22
CFalse
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand pin setup and input reading

    Pin 22 is set as input. When the button is pressed, the pin reads HIGH, so GPIO.input(22) returns True.
  2. Step 2: Check the print output

    The variable state holds True, so print(state) outputs True.
  3. Final Answer:

    True -> Option A
  4. Quick Check:

    Pressed button = True output [OK]
Quick Trick: Pressed button means pin HIGH, so GPIO.input returns True [OK]
Common Mistakes:
  • Assuming pressed means False
  • Confusing pin number with state
  • Expecting numeric output instead of boolean

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes