Bird
0
0

You want to control two LEDs connected to GPIO pins 20 and 21. Which code correctly turns ON pin 20 and turns OFF pin 21 simultaneously using GPIO.output()?

hard📝 Application Q9 of 15
Raspberry Pi - GPIO Basics with Python
You want to control two LEDs connected to GPIO pins 20 and 21. Which code correctly turns ON pin 20 and turns OFF pin 21 simultaneously using GPIO.output()?
AGPIO.output(20, GPIO.HIGH) GPIO.output(21, GPIO.HIGH)
BGPIO.output([20, 21], [GPIO.HIGH, GPIO.LOW])
CGPIO.output(20, 0) GPIO.output(21, 1)
DGPIO.output(20, GPIO.LOW) GPIO.output(21, GPIO.HIGH)
Step-by-Step Solution
Solution:
  1. Step 1: Understand GPIO.output supports list inputs

    GPIO.output can take a list of pins and a list of states to set multiple pins at once.
  2. Step 2: Verify correct pin-state pairs

    GPIO.output([20, 21], [GPIO.HIGH, GPIO.LOW]) sets pin 20 HIGH and pin 21 LOW simultaneously.
  3. Final Answer:

    GPIO.output([20, 21], [GPIO.HIGH, GPIO.LOW]) -> Option B
  4. Quick Check:

    GPIO.output accepts lists for multiple pins [OK]
Quick Trick: Use lists in GPIO.output to set multiple pins at once [OK]
Common Mistakes:
  • Calling GPIO.output separately for each pin
  • Swapping HIGH and LOW states
  • Using numeric 1 and 0 instead of GPIO constants

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes