Bird
0
0

What will be the output of this code snippet?

medium📝 Predict Output Q13 of 15
Raspberry Pi - GPIO Basics with Python
What will be the output of this code snippet?
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7, GPIO.OUT)
print(GPIO.gpio_function(7))

Assuming pin 7 is set as output.
A0
B3
C2
D1
Step-by-Step Solution
Solution:
  1. Step 1: Understand GPIO.gpio_function()

    This function returns a number representing the pin's current function. For output pins, it returns 1.
  2. Step 2: Check pin setup

    Pin 7 is set as GPIO.OUT, so gpio_function(7) returns 1.
  3. Final Answer:

    1 -> Option D
  4. Quick Check:

    Output pin function code = 1 [OK]
Quick Trick: Output pins return 1 from gpio_function() [OK]
Common Mistakes:
  • Assuming gpio_function returns pin number
  • Confusing output code with input code
  • Not setting pin mode before calling gpio_function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes