Color Mixer (Update)

Last week’s assignment was "re-packaged" into the soap box.  Few steps were necessary for this to work.

The LED was cut and a wire was attached to each leg:

Cimg1951_2

Holes were drilled into the lid, and the sensor was glued:

Cimg1956Cimg1957

Cimg1955
Cimg1954

http://vimeo.com/moogaloop.swf?clip_id=1971198&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=ffffff&fullscreen=1
Color Mixer in Soap Box from Fuki on Vimeo.

The following was posted on 10/07/2008

I used two bicolor LED lights and one yellow LED light.  The bicolor
LED turns red at 635nm in forward voltage (?); and it turns green at
565nm in reversed voltage (? again, i’m not sure what this means, but I
switched the ground and power of the LED, and it works).

Cimg1927Cimg1929
Cimg1921

Code:

int redPin = 9;   // Red/Green bicolor LED,   connected to digital pin 9
int yellPin = 10;  // yellow LED, connected to digital pin 10
int grnPin = 11;  // Red/Green bicolor LED,  connected to digital pin 11

// Program variables
int redVal = 0;   // Variables to store the values to send to the pins
int yellVal = 0;
int grnVal = 0;

float DEBUG = 1;          // Set to 1 to turn on debugging output

void setup()
{
  pinMode(redPin, OUTPUT);   // sets the pins as output
  pinMode(yellPin, OUTPUT);   
  pinMode(grnPin, OUTPUT);

  if (DEBUG) {           // If we want to see the pin values for debugging…
    Serial.begin(9600);  // …set up the serial ouput in 0004 format
  }
}

// Main program
void loop()
{
  potVal = analogRead(potPin);   // read the potentiometer value at the input pin

  if (potVal < 333)  // Lowest third of the potentiometer’s range (0-333)
  {                  
    potVal = (potVal * 3) / 1.57  ; // Normalize to 0-635

    redVal = 635.0 – potVal;  // bicolor from full to off
    yellVal = potVal;        // Green from off to full
    grnVal = 0;             // Blue off
  }
  else if (potVal < 666) // Middle third of potentiometer’s range (333-666)
  {
    potVal = ( (potVal-332) * 3) / 4; // Normalize to 0-255

    redVal = 0;            // Red off
    yellVal = 256 – potVal; // Green from full to off
    grnVal = potVal;       // Blue from off to full
  }
  else  // Upper third of potentiometer"s range (667-1000)
  {
    potVal = ( (potVal-683) * 3) / 1.39; // Normalize to 0-683

    redVal = potVal;       // Red from off to full
    yellVal = 0;            // Green off
    grnVal = 565.0 – potVal; // Blue from full to off
  }
  analogWrite(redPin, redVal);   // Write values to LED pins
  analogWrite(yellPin, yellVal);
  analogWrite(grnPin, grnVal);

  if (DEBUG) { // If we want to read the output
    DEBUG += 1.0;      // Increment the DEBUG counter
    if (DEBUG > 100.0) // Print every hundred loops
    {
      DEBUG = 1;     // Reset the counter
                             // Serial output using 0004-style functions
      Serial.print("R:");    // Indicate that output is red value
      Serial.print(redVal);  // Print red value
      Serial.print("\t");    // Print a tab
      Serial.print("G:");    // Repeat for grn and blu…
      Serial.print(yellVal);
      Serial.print("\t");   
      Serial.print("B:");   
      Serial.println(grnVal); // println, to end with a carriage return
    }
  }
}