Bird
0
0

Given the code snippet below, why will it raise an error when executed?

medium📝 Debug Q7 of 15
Raspberry Pi - Automation and Scheduling
Given the code snippet below, why will it raise an error when executed?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.output(16, GPIO.HIGH)
AGPIO pin 16 is already in use by another process
BGPIO pin 16 was not set as output before writing
CGPIO.HIGH is an invalid value for output
DGPIO.setmode() was not called
Step-by-Step Solution
Solution:
  1. Step 1: Check GPIO setup sequence

    GPIO pins must be configured as input or output before writing values.
  2. Step 2: Identify missing setup

    The code misses GPIO.setup(16, GPIO.OUT), so output() call fails.
  3. Final Answer:

    GPIO pin 16 was not set as output before writing -> Option B
  4. Quick Check:

    Always setup pin mode before output [OK]
Quick Trick: Setup pin mode before output [OK]
Common Mistakes:
MISTAKES
  • Forgetting GPIO.setup() before GPIO.output()
  • Assuming setmode() alone configures pins

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes