Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the GPIO library for Raspberry Pi.
Raspberry Pi
import [1] as GPIO
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'time' instead of the GPIO library.
Using 'gpiozero' which is a different GPIO library.
✗ Incorrect
The RPi.GPIO library is used to control the GPIO pins on a Raspberry Pi for hardware projects like traffic lights.
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 which refers to physical pin numbers.
Using GPIO.OUT which is for pin direction, not mode.
✗ Incorrect
Setting GPIO mode to GPIO.BCM means we use the Broadcom chip's pin numbering.
3fill in blank
hardFix the error in setting up pin 17 as an output.
Raspberry Pi
GPIO.setup([1], GPIO.OUT) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 18 instead of 17.
Using GPIO.OUT as pin number.
✗ Incorrect
Pin 17 is the correct GPIO pin number to set as output for the traffic light LED.
4fill in blank
hardFill both blanks to turn on the green LED connected to pin 22.
Raspberry Pi
GPIO.output([1], [2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 17 instead of 22.
Setting output to GPIO.LOW which turns the LED off.
✗ Incorrect
Pin 22 controls the green LED. Setting output to GPIO.HIGH turns it on.
5fill in blank
hardFill all three blanks to create a dictionary mapping LED colors to their GPIO pins.
Raspberry Pi
led_pins = { [1]: [2], [3]: 22 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'yellow' instead of 'green' as a key.
Mixing up pin numbers.
✗ Incorrect
The dictionary maps 'red' to pin 17 and 'green' to pin 22 for the traffic lights.