RGB LED Sliders
Made by Leslie Liu
Made by Leslie Liu
To explore using multiple inputs to control an output.
Created: November 11th, 2024
Using three slide potentiometers as input sources, I sought to replicate the skeuomorph/interface metaphor of the digital RGB slider/controller.
The code for this project was relatively straightforward; after consulting the Photon 2 datasheet I was able to rewire my analog potentiometer readings correctly. The main hurdle emerged in the RGB LED itself — as my first time working with an RGB LED, I was reluctant to go rougher and bend the pins — but after some help from Zhenfang (!! major shoutout), got it working.
int rPin=D16;
int gPin=D15;
int bPin=A5;
int rMax = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int gMax = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int bMax = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int rLum = 0;
int gLum = 0;
int bLum = 0;
int potPinR = A2;
int potPinG = A1;
int potPinB = A0;
// Create a variable to hold the pot reading
int potRdgR = 0;
int potRdgG = 0;
int potRdgB = 0;
void setup()
{
// Set up our pins for output
pinMode(rPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
// turn them all off...
analogWrite(rPin, rMax);
analogWrite(gPin, gMax);
analogWrite(bPin, bMax);
// pot reading
Particle.variable("potR",potRdgR);
Particle.variable("potG",potRdgG);
Particle.variable("potB",potRdgB);
}
void loop()
{
potRdgR = analogRead(potPinR);
potRdgG = analogRead(potPinG);
potRdgB = analogRead(potPinB);
rLum = map(potRdgR,0,4095,0,255);
gLum = map(potRdgG,0,4095,0,255);
bLum = map(potRdgB,0,4095,0,255);
analogWrite(rPin, 255-rLum);
analogWrite(gPin, 255-gLum);
analogWrite(bPin, 255-bLum);
delay(100);
}
Click to Expand
This project showed me the importance of having a rigorous and clear debugging process/workflow (see video below). After fiddling with the breadboard for a while, I hadn't been able to get the bulb to work properly. By starting with a careful read through my code, then checking the physical component itself, and finally considering the wiring, I was able to gradually troubleshoot. This process also deepened my appreciation for hardware/those who work with physical materials, as it reflects the ethos of "knowing one's material."
To explore using multiple inputs to control an output.