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 - Arduino Tutorial
From the course: Learning Arduino: Pulse Width Modulation
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Fading an LED with PWM with code3m 5s
-
(Locked)
Calibrating an analog input to fade an LED precisely3m 35s
-
(Locked)
Challenge: Programming an LED that reacts to brightness54s
-
(Locked)
Solution: Programming an LED that reacts to brightness2m 45s
-
(Locked)
Using an RGB LED3m 49s
-
(Locked)
Mixing colors on an RGB LED using three analog inputs1m 43s
-
(Locked)
Challenge: Fading through the rainbow with PWM51s
-
(Locked)
Solution: Fading through the rainbow with PWM2m 21s
-
-
-