From the course: Learning Arduino: Pulse Width Modulation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Mixing colors on an RGB LED using three analog inputs

Mixing colors on an RGB LED using three analog inputs - Arduino Tutorial

From the course: Learning Arduino: Pulse Width Modulation

Start my 1-month free trial

Mixing colors on an RGB LED using three analog inputs

- Let's take our color mixing to the next level, and add some analog inputs. In the Arduino IDE, I will select File, examples, starter kit, color mixing lamp. This program calls for three photosensors to be connected to analog 0, 1 and 2. I am going to use three potentiometers instead, so I can more precisely control the change of color. In the code I need to change the value of green LED pin, red LED pin and blue LED pin so that they correspond to the correct anode for each color. If we scroll down to the loop we can see what's going on. Rather than using the map command, this program is simply dividing by four which roughly gets the job done. These values are also printed to the serial monitor. I'll upload the program and open the serial monitor. Each potentiometer is turned all the way down so each value is reading zero. Now, i will slowly turn up the red LED. And that looks like a nice place to stop. Next, I'll ring up the green LED. As the brightness increases, the added green…

Contents