0
0
Raspberry Piprogramming~10 mins

Multiple LED patterns 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 turn on the LED connected to GPIO pin 17.

Raspberry Pi
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, [1])
Drag options to blanks, or click blank then click option'
A0
BTrue
CFalse
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using False instead of True turns the LED off.
Using 0 or None does not turn the LED on.
2fill in blank
medium

Complete the code to make the LED blink once with a 1 second delay.

Raspberry Pi
import time
GPIO.output(18, True)
time.sleep([1])
GPIO.output(18, False)
Drag options to blanks, or click blank then click option'
A1
B2
C0
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 means no delay, LED turns off immediately.
Using 2 makes the LED stay on too long for this task.
3fill in blank
hard

Fix the error in the code to blink the LED 3 times with 0.5 second intervals.

Raspberry Pi
for i in range(3):
    GPIO.output(22, [1])
    time.sleep(0.5)
    GPIO.output(22, False)
    time.sleep(0.5)
Drag options to blanks, or click blank then click option'
A0
BNone
CFalse
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using False keeps the LED off.
Using None or 0 does not turn the LED on.
4fill in blank
hard

Fill both blanks to create a dictionary mapping LED pins to their on/off status for a pattern.

Raspberry Pi
led_pattern = {17: [1], 27: [2]
Drag options to blanks, or click blank then click option'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using None or 0 does not correctly represent on/off states.
Using False for both turns off all LEDs.
5fill in blank
hard

Fill all three blanks to create a loop that cycles LEDs on pins 5, 6, and 13 on and off with 0.3 second delay.

Raspberry Pi
pins = [5, 6, 13]
for pin in pins:
    GPIO.output(pin, [1])
    time.sleep([2])
    GPIO.output(pin, [3])
Drag options to blanks, or click blank then click option'
AFalse
B0.3
CTrue
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 second delay is too long for this pattern.
Swapping True and False reverses LED states.