0
0
Raspberry Piprogramming~10 mins

Why GPIO programming is foundational in Raspberry Pi - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set up a GPIO pin as output.

Raspberry Pi
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup([1], GPIO.OUT)
Drag options to blanks, or click blank then click option'
Apin
BGPIO
C18
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GPIO' instead of a pin number
Using 'input' instead of a pin number
2fill in blank
medium

Complete the code to turn on an LED connected to a GPIO pin.

Raspberry Pi
GPIO.output(18, [1])
Drag options to blanks, or click blank then click option'
AGPIO.IN
BGPIO.HIGH
CLOW
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN which is for input mode
Using LOW which turns off the LED
3fill in blank
hard

Fix the error in the code to clean up GPIO settings.

Raspberry Pi
GPIO.[1]()
Drag options to blanks, or click blank then click option'
Acleanup
Bclear
Creset
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'clear' or 'reset' which are not valid GPIO functions
4fill in blank
hard

Fill both blanks to create a dictionary of pin states for pins 17 and 27.

Raspberry Pi
pin_states = {17: GPIO.[1], 27: GPIO.[2]
Drag options to blanks, or click blank then click option'
AHIGH
BLOW
CIN
DOUT
Attempts:
3 left
💡 Hint
Common Mistakes
Using IN or OUT which are modes, not states
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps pin numbers to their output states if the state is HIGH.

Raspberry Pi
active_pins = {pin: state for pin, state in pin_states.items() if state == GPIO.[1] and pin != [2] and pin != [3]
Drag options to blanks, or click blank then click option'
ALOW
B17
C27
DHIGH
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW instead of HIGH
Using pin names instead of numbers