0
0
Raspberry Piprogramming~10 mins

Single LED control 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.

Raspberry Pi
import [1] as GPIO
Drag options to blanks, or click blank then click option'
ARPi.GPIO
Bgpiozero
Ctime
Dos
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated libraries like 'time' or 'os'.
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.BOARD
BGPIO.IN
CGPIO.OUT
DGPIO.BCM
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.BOARD instead of GPIO.BCM.
Confusing mode constants with pin direction constants.
3fill in blank
hard

Fix the error in setting up pin 18 as output.

Raspberry Pi
GPIO.setup(18, [1])
Drag options to blanks, or click blank then click option'
AGPIO.OUT
BGPIO.PWM
CGPIO.INPUT
DGPIO.IN
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.IN or GPIO.INPUT which are for input pins.
Using GPIO.PWM which is for pulse-width modulation, not basic output.
4fill in blank
hard

Complete the code to turn the LED on connected to pin 18.

Raspberry Pi
GPIO.output(18, [1])
GPIO.cleanup()
Drag options to blanks, or click blank then click option'
AGPIO.HIGH
BGPIO.LOW
C18
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW to turn the LED on (it turns it off).
Passing the pin number to cleanup which expects no arguments.
5fill in blank
hard

Fill all three blanks to blink the LED once with a 1 second delay.

Raspberry Pi
GPIO.output([1], GPIO.HIGH)
time.sleep([2])
GPIO.output([3], GPIO.LOW)
Drag options to blanks, or click blank then click option'
A18
B1
C17
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using different pin numbers for on and off.
Using too short or too long delay values.