a colorful desk lamp
Introduction
In this project, we will use two potentiometers to control the color and brightness of the colored lights.
For this project, we will be using the HSL color model, which is an intuitive color model that divides the attributes of color into three parts: hue, saturation, and lightness.
Project Objectives
- Reading values from potentiometers
- Controlling the color and brightness of an RGB light
- Understanding the HSL color model
Required Materials
- FutureBoard Lite
- RGB Light Module
- Potentiometer Module x 2
- PH2.0 Connecting Wire x 3
Circuit Wiring
Structural Assembly
Build the structure of a lamp using building blocks; you can refer to the picture below, but it doesn't have to be built exactly the same.
Project Code
Project Link: desk_lamp
Upon opening, an error message will be displayed (Microsoft emulator has not recognized new hardware information); choose to ignore.
Code Interpretation
First, create a new background and draw a desk lamp.
Then create two new knob characters for them to say the values of the two knobs.
Lastly, set the pin assignment for the light ring.
For hue, the range is 0-360, and for luminosity, the range is 0-100.
In an infinite loop, read the values of the left and right knobs, and map their values to 0-360 and 0-100 respectively.
Implementation Effect
Twist the left knob to change the color, and the right knob to adjust the brightness.
At the same time, the screen will display the corresponding values of both knobs.