Building on-top of the basic RGB tutorial, let us take the RGB LED control to the next level by diving into color mixing using the Adafruit NeoPixel library and Mercury Board. Instead of showing static red, green, and blue lights, weโll blend these base colors in different proportions to create a wide range of custom colors.
By adjusting the intensity of red, green, and blue components, you can create beautiful hues like purple, cyan, yellow โ and even white. This concept is not only fun to play with but also fundamental to how screens, smart lights, and digital displays work.
โจ Letโs turn your Mercury Board into a digital color palette! ๐ด๐ก๐ข
By the end of this tutorial, youโll learn:โ How to control and do color mixing of WS2812 - onboard RGBLED on Mercury using Adafruit NeoPixel Library.
Quick Video TutorialLet's Get Started- Setting up the environment - if you haven't added the Mercury Board on your Arduinoยฎ, this is a good time to do so. Refer to this tutorial for setup: https://www.hackster.io/ral/getting-started-with-mercury-arduino-setup-705f4d
- Plug the USB Cable to Mercury Board and connect it you your laptop.
- To initiate upload process, press and hold FLASH button when "Connecting..." is visible on Arduino Terminal.
- Basic RGB Tutorial: https://www.hackster.io/ral/rgb-led-magic-with-mercury-board-adafruit-neopixel-77075f
Crash Course: Color mixing of RGB Light
Color mixing with RGB LEDs is based on the principle of additive color mixing, where different intensities of Red, Green, and Blue light are combined to produce a wide spectrum of colors. Each of these colors can be adjusted independently from 0 (off) to 255 (fully on), giving you over 16 million possible color combinations!
๐ด๐ข๐ต The RGB Color ModelHereโs how the primary colors mix:
- Red (255, 0, 0)
- Green (0, 255, 0)
- Blue (0, 0, 255)
When you combine them:
- Red + Green = Yellow (255, 255, 0)
- Red + Blue = Magenta (255, 0, 255)
- Green + Blue = Cyan (0, 255, 255)
- Red + Green + Blue = White (255, 255, 255)
And of course:
All Off = Black (0, 0, 0)
Lets consider Yellow for a moment, on mixing 100% intensity or Red Light ๐ด with 100% intensity of Green Light ๐ข, you should in theory get Yellow Light ๐ก. But, every hardware has some variability in what light it can produce. Thus in our case, we use the following percentages of Red and Green light to produce Yellow/Amber Light:
pixels.setPixelColor(0, pixels.Color(255, 90, 0, 0));
A deeper dive into the code...To simulate a traffic signal ๐ฆ, weโll recreate the familiar sequence:
- Green Light ๐ข stays ON for 2 seconds โ indicating that vehicles can move.
- Yellow Light ๐ก lights up for 1 second โ warning that the signal is about to change.
- Red Light ๐ด stays ON for 2 seconds โ signaling traffic to stop and wait for the next green.
This simple timing-based pattern mimics real-world traffic behavior and is a great way to practice controlling RGB LEDs with delays and logic!
void loop() {
pixels.setPixelColor(0, pixels.Color(0, 255, 0, 0)); // Green
pixels.show();
delay(2000);
pixels.setPixelColor(0, pixels.Color(255, 90, 0, 0)); // Yellow/Amber
pixels.show();
delay(1000);
pixels.setPixelColor(0, pixels.Color(255, 0, 0, 0)); // Red
pixels.show();
delay(2000);
}
Why This MattersUnderstanding RGB mixing is key for:
- Designing custom LED animations
- Creating visual notifications
- Building interactive art or ambient light systems
- Programming smart lighting for wearables or IoT projects
Itโs the foundation of digital displays and lighting โ and now, youโre learning to master it at the hardware level.
_____
Stay tuned for more tutorial coming up in future!!!
Comments