RGB LED Sliders

Made by Leslie Liu

To explore using multiple inputs to control an output.

Created: November 11th, 2024

0

Intention

Using three slide potentiometers as input sources, I sought to replicate the skeuomorph/interface metaphor of the digital RGB slider/controller.

0

Process

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.

0
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
0

Outcome

My final circuit includes 1 RGB LED modulated by 3 1KΩ resistors; the LED's color is determined by three small slide potentiometers; and it is all connected via jumper wires to the power rail.

0

Overhead view of the circuit.

0

Perspectival view of interaction. Each slide potentiometer represents red, green, and blue respectively; making physical a gesture that feels more familiar in digital contexts (e.g. photo-editing/image making software).

0

Overhead view of sliders as inputs.

0

Reflection

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."

x