Holi color mixer on an Arduino Uno
Three knobs mix red, green and blue light into any color on a ring of WS2812B LEDs, and a button throws a splash of bright Holi colors across it. The whole build, an Arduino Uno and 6 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Holi color-mixing light: three knobs mix red, green and blue light into any
// color on a ring of LEDs, and a button throws a splash of bright colors
// across it, the way gulal powder flies at Holi.
//
// knobs three potentiometers, wipers -> A0 (red), A1 (green), A2 (blue)
// button pin 2 -> button -> GND (INPUT_PULLUP)
// ring 12 WS2812B LEDs, DIN <- 330 ohms <- pin 6
//
// Holi, the festival of colors, welcomes spring with friends and family
// throwing colored powder and water at each other until everyone is every
// color at once. Light mixes differently from powder: paint and powder get
// darker as you mix them, but light adds up. Red and green light make yellow,
// red and blue make magenta, green and blue make cyan, and all three make
// white. Turn the knobs and see.
//
// The splash picks random colors from a palette of bright Holi shades and
// lands each one on a random LED, then the ring fades back to your mix.
//
// Things to try. Turn red and green up with blue down: yellow. Press the
// button for a splash. Add your favorite color to SPLASH.
#include <Adafruit_NeoPixel.h>
const int BUTTON_PIN = 2;
const int LEDS = 12;
Adafruit_NeoPixel ring(LEDS, 6, NEO_GRB + NEO_KHZ800);
const uint32_t SPLASH[] = {0xFF1493, 0xFFD700, 0x00C853, 0x2979FF, 0xFF6D00, 0xAA00FF, 0x00E5FF};
const int SHADES = sizeof(SPLASH) / sizeof(SPLASH[0]);
uint8_t splashLeft[LEDS]; // frames each LED keeps its splash color
uint32_t splashColor[LEDS];
uint32_t lastMix = 0xFFFFFFFF;
int splashes = 0;
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
ring.begin();
ring.setBrightness(160);
Serial.println("Holi color mixer: turn the knobs, press for a splash");
}
void loop() {
uint8_t r = analogRead(A0) / 4;
uint8_t g = analogRead(A1) / 4;
uint8_t b = analogRead(A2) / 4;
uint32_t mix = ring.Color(r, g, b);
if (digitalRead(BUTTON_PIN) == LOW) {
splashes++;
for (int n = 0; n < 8; n++) {
int i = random(0, LEDS);
splashColor[i] = SPLASH[random(0, SHADES)];
splashLeft[i] = random(20, 60);
}
Serial.print("Splash ");
Serial.println(splashes);
while (digitalRead(BUTTON_PIN) == LOW) delay(10);
}
for (int i = 0; i < LEDS; i++) {
if (splashLeft[i] > 0) {
splashLeft[i]--;
ring.setPixelColor(i, splashColor[i]);
} else {
ring.setPixelColor(i, mix);
}
}
ring.show();
// Report the mix when it changes by more than a little.
if ((mix >> 20) != (lastMix >> 20) || ((mix >> 12) & 0xF) != ((lastMix >> 12) & 0xF) || ((mix >> 4) & 0xF) != ((lastMix >> 4) & 0xF)) {
lastMix = mix;
Serial.print("Mix red ");
Serial.print(r);
Serial.print(" green ");
Serial.print(g);
Serial.print(" blue ");
Serial.println(b);
}
delay(20);
}
Parts list
8 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Full-size breadboard
- 3 × Potentiometer
- 1 × Resistor, 330 Ω
- 1 × Pushbutton
- 1 × Addressable RGB LEDs
How it is wired
8 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 6; Resistor, 330 Ω pin 1
- Arduino Uno R3 pin 2; Pushbutton pin 1a
- Arduino Uno R3 pin 5V; Potentiometer (1) pin 3; Potentiometer (2) pin 3; Potentiometer (3) pin 3; Addressable RGB LEDs pin VDD
- Ground: Arduino Uno R3 pin GND; Potentiometer (1) pin 1; Potentiometer (2) pin 1; Potentiometer (3) pin 1; Pushbutton pin 2a; Addressable RGB LEDs pin VSS
- Arduino Uno R3 pin A0; Potentiometer (1) pin 2
- Arduino Uno R3 pin A1; Potentiometer (2) pin 2
- Arduino Uno R3 pin A2; Potentiometer (3) pin 2
- Resistor, 330 Ω pin 2; Addressable RGB LEDs pin DIN
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.