0
0
Raspberry Piprogramming~20 mins

RGB LED color mixing in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
RGB LED Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this RGB LED color mixing code?

Consider this Python code controlling an RGB LED on a Raspberry Pi. What color will the LED show?

Raspberry Pi
red = 255
green = 100
blue = 0

if red > green and red > blue:
    color = 'Red'
elif green > red and green > blue:
    color = 'Green'
else:
    color = 'Blue'

print(color)
ARed
BGreen
CNo color
DBlue
Attempts:
2 left
💡 Hint

Check which color value is the highest number.

Predict Output
intermediate
2:00remaining
What is the combined color output for these RGB values?

This code mixes RGB values to create a color. What is the printed output?

Raspberry Pi
def mix_color(r, g, b):
    return f'#{r:02X}{g:02X}{b:02X}'

color_code = mix_color(0, 128, 128)
print(color_code)
A#808000
B#800080
C#008080
D#000000
Attempts:
2 left
💡 Hint

Look at the hexadecimal format for green and blue values.

🔧 Debug
advanced
2:00remaining
Why does this RGB LED code cause an error?

Find the error in this Raspberry Pi RGB LED control code and identify the error type.

Raspberry Pi
red = 255
green = 255
blue = 255

color = {red, green, blue}
print(color)
ANameError
BSyntaxError
CTypeError
DIt prints a set of values
Attempts:
2 left
💡 Hint

Look at the curly braces and what they create in Python.

Predict Output
advanced
2:00remaining
What is the output of this PWM brightness adjustment code?

This code adjusts brightness of an RGB LED using PWM values. What is printed?

Raspberry Pi
brightness = 0.5
red = int(255 * brightness)
green = int(100 * brightness)
blue = int(50 * brightness)

print(red, green, blue)
A127 50 25
B128 50 25
C127 49 25
D128 49 25
Attempts:
2 left
💡 Hint

Remember int() truncates decimals down.

🧠 Conceptual
expert
2:00remaining
Which option correctly describes additive color mixing for RGB LEDs?

When mixing colors with RGB LEDs, which statement is true?

AAdding green and blue light produces red light.
BAdding red and green light produces yellow light.
CAdding red and green light produces cyan light.
DAdding red and blue light produces green light.
Attempts:
2 left
💡 Hint

Think about how light colors combine, not paint.