Bird
0
0

You want to write a program that reads a button connected to GPIO pin 17 (BCM numbering) and turns on an LED on pin 27 when pressed. Which setup code is correct?

hard📝 Application Q9 of 15
Raspberry Pi - GPIO Basics with Python
You want to write a program that reads a button connected to GPIO pin 17 (BCM numbering) and turns on an LED on pin 27 when pressed. Which setup code is correct?
AGPIO.setmode(GPIO.BOARD) GPIO.setup(17, GPIO.IN) GPIO.setup(27, GPIO.OUT)
BGPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.setup(27, GPIO.IN)
CGPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN) GPIO.setup(27, GPIO.OUT)
DGPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN) GPIO.setup(13, GPIO.OUT)
Step-by-Step Solution
Solution:
  1. Step 1: Understand pin numbering and roles

    Button is on GPIO 17 input, LED on GPIO 27 output, both BCM numbering.
  2. Step 2: Check mode and setup calls

    GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN) GPIO.setup(27, GPIO.OUT) sets mode to BCM and configures pin 17 as input and 27 as output correctly.
  3. Step 3: Evaluate other options

    GPIO.setmode(GPIO.BOARD) GPIO.setup(17, GPIO.IN) GPIO.setup(27, GPIO.OUT) uses BOARD mode but pins 17 and 27 are BCM numbers, so mismatch. GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) GPIO.setup(27, GPIO.IN) swaps input/output roles. GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN) GPIO.setup(13, GPIO.OUT) uses BOARD pins 11 and 13, unrelated.
  4. Final Answer:

    GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.IN) GPIO.setup(27, GPIO.OUT) -> Option C
  5. Quick Check:

    Correct BCM setup for button and LED = B [OK]
Quick Trick: Match pin numbers with mode and roles carefully [OK]
Common Mistakes:
  • Mixing BOARD and BCM modes
  • Swapping input and output pins
  • Using wrong pin numbers for mode

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes