Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the GPIO library.
Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated libraries like 'time' or 'sys' instead of GPIO library.
✗ Incorrect
The RPi.GPIO library is used to control the Raspberry Pi GPIO pins.
2fill in blank
mediumComplete the code to set the GPIO mode to BCM numbering.
Raspberry Pi
GPIO.setmode([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.BOARD instead of GPIO.BCM for BCM numbering.
✗ Incorrect
GPIO.BCM sets the pin numbering to Broadcom SOC channel numbers.
3fill in blank
hardFix the error in setting up the button pin as input with pull-up resistor.
Raspberry Pi
GPIO.setup(18, [1], pull_up_down=GPIO.PUD_UP)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the pin as output instead of input.
✗ Incorrect
The button pin must be set as input (GPIO.IN) with pull-up resistor enabled.
4fill in blank
hardFill both blanks to toggle the LED state when the button is pressed.
Raspberry Pi
if GPIO.input(18) == [1]: led_state = not [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for GPIO.HIGH instead of GPIO.LOW for button press.
Toggling wrong variable.
✗ Incorrect
The button is pressed when input is LOW (due to pull-up). We toggle the current LED state.
5fill in blank
hardFill all three blanks to set up the LED pin, initialize its state, and update it.
Raspberry Pi
GPIO.setup([1], GPIO.OUT) led_state = [2] GPIO.output([3], led_state)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong pin number.
Starting LED state as True instead of False.
✗ Incorrect
Pin 17 is used for LED output. Initial state is off (False). We output the state to pin 17.