Skip to main content

a colorful desk lamp

arcade_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

Circuit Wiring

arcade_lamp_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.

lamp_assembly

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.

error.png

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.

code

For hue, the range is 0-360, and for luminosity, the range is 0-100.

lamp_RGB

In an infinite loop, read the values of the left and right knobs, and map their values to 0-360 and 0-100 respectively.

lamp_code

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.

kittenbot_arcade_lamp