0
0
Raspberry Piprogramming~10 mins

RGB LED color mixing 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 set the red LED pin as an output.

Raspberry Pi
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup([1], GPIO.OUT)
Drag options to blanks, or click blank then click option'
A18
B17
C22
D27
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong GPIO pin number.
Forgetting to set the pin as output.
2fill in blank
medium

Complete the code to turn on the green LED.

Raspberry Pi
GPIO.output([1], GPIO.HIGH)
Drag options to blanks, or click blank then click option'
A17
B27
C22
D18
Attempts:
3 left
💡 Hint
Common Mistakes
Using GPIO.LOW instead of GPIO.HIGH.
Using the wrong pin number.
3fill in blank
hard

Fix the error in the code to turn off the blue LED.

Raspberry Pi
GPIO.output([1], GPIO.LOW)
Drag options to blanks, or click blank then click option'
A18
B27
C22
D17
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong pin number for the blue LED.
Using GPIO.HIGH instead of GPIO.LOW.
4fill in blank
hard

Fill both blanks to create a dictionary mapping colors to their GPIO pins.

Raspberry Pi
led_pins = [1]: 17, [2]: 22, 'blue': 18}
Drag options to blanks, or click blank then click option'
A'red'
B'yellow'
C'green'
D'white'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect color names as keys.
Forgetting quotes around string keys.
5fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps colors to their pin states when turned on.

Raspberry Pi
led_states = [2]: GPIO.HIGH for [2], {{BLANK_4}} in led_pins.items()
Drag options to blanks, or click blank then click option'
A{
Bcolor
Cpin
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of curly braces.
Mixing up variable names in the loop.