0
0
Raspberry Piprogramming~10 mins

Traffic light simulation in Raspberry Pi - Interactive Code Practice

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

Complete 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'
Agpiozero
Bsys
Ctime
DRPi.GPIO
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'time' instead of the GPIO library.
Using 'gpiozero' which is a different GPIO library.
2fill in blank
medium

Complete 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'
AGPIO.OUT
BGPIO.BCM
CGPIO.BOARD
DGPIO.IN
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.
3fill in blank
hard

Fix 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'
A17
B18
CGPIO.OUT
DGPIO.IN
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 18 instead of 17.
Using GPIO.OUT as pin number.
4fill in blank
hard

Fill 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'
A22
BGPIO.HIGH
CGPIO.LOW
D17
Attempts:
3 left
💡 Hint
Common Mistakes
Using pin 17 instead of 22.
Setting output to GPIO.LOW which turns the LED off.
5fill in blank
hard

Fill 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'
A'red'
B17
C'green'
D'yellow'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'yellow' instead of 'green' as a key.
Mixing up pin numbers.