Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GPIO' instead of a pin number
Using 'input' instead of a pin number
✗ Incorrect
GPIO pins are identified by numbers like 18. This code sets pin 18 as an output pin.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN which is for input mode
Using LOW which turns off the LED
✗ Incorrect
Setting the pin to GPIO.HIGH turns the LED on by sending voltage.
3fill in blank
hardFix the error in the code to clean up GPIO settings.
Raspberry Pi
GPIO.[1]() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'clear' or 'reset' which are not valid GPIO functions
✗ Incorrect
GPIO.cleanup() resets the GPIO pins to a safe state after use.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using IN or OUT which are modes, not states
✗ Incorrect
This dictionary shows pin 17 is HIGH (on) and pin 27 is LOW (off).
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOW instead of HIGH
Using pin names instead of numbers
✗ Incorrect
This code filters pins that are HIGH and excludes pins 17 and 27.