03 Color Mixer updated

Color Mixer with IR sensor and Fullcolor Led in the same Gummy Bear Box.

http://vimeo.com/moogaloop.swf?clip_id=1905269&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
FullColor+IR Sensor Color Mixer from Hsiang Ju Hung on Vimeo.
Code is modified from the previous one.  Because the output voltage from IR sensor is about from 0 to 3 instead of regular range of 0 to 5. So I tried to justify it to make RGB reach full 255.
Code is here:Download IRsensor_Fullcolor

http://vimeo.com/moogaloop.swf?clip_id=1853222&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1

Color Mixer from Hsiang Ju Hung on Vimeo.

Dscf9940

Dscf9938

Material: Gummy Bear box, Led, Tissue, Arduino Board, Potentiometer, Resistors, 9V Battery, Wires.
Code is modified from Arduino Example Code

———————————–

// Input settings
int analogPin = 3;   // potentiometer connected to analog pin 3
int val = 0;         // variable to store the read value

// Digital pin settings
int aOut = 9;   // LEDs connected to digital pins 9, 10 and 11
int bOut = 10;  //
int cOut = 11;

// Variables
int aVal = 0;   // Variables to store the input from the potentiometers
int bVal = 0; 
int cVal = 0;

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

void setup()
{
  pinMode(aOut, OUTPUT);   // sets the pin as output
  pinMode(bOut, OUTPUT);   // sets the pin as output
  pinMode(cOut, OUTPUT);   // sets the pin as output
 
  if (DEBUG) {
    Serial.begin(9600);  }    // Open serial communication for reporting
}

//Main program
void loop(){
  val = analogRead(analogPin);   // read the input pin
 
  if(val < 341){         // first range = 0-340
    val = (val*3)/4;     // justify the range from 0-340 to 0-255;
    aVal = 256 – val;  // a changes from 255 to 1
    bVal = val;          // b changes from 0 to 255
    cVal = 1;            // c is 1
  }
  else if(val < 682){  //second range = 341-681
    val = ((val-341))*3/4;//justify the range from341-681 to 0-255;
    aVal = 1;           // a is 1
    bVal = 256 – val;   // b is from 255 to 1
    cVal = val;         // c is from 0 to 255
  }
  else{                 // third range = 682-1024
    val = ((val-683)*3)/4;//justify the range from341-681 to 0-255;
    aVal = val;           // a is from 0 to 255
    bVal = 1;             // b is 1
    cVal = 256 – val;     // c is from 255 to 1
  }
  if (DEBUG) {      // if we want to read the output
    DEBUG+=1;      
    if(DEBUG>100){  //print every hunderd loops
      DEBUG = 1;    // reset the counter
      Serial.print("val:");
      Serial.print(val);
      Serial.print(" A:");
      Serial.print(aVal);
      Serial.print(" B:");
      Serial.print(bVal);
      Serial.print(" C:");
      Serial.print(cVal);
      Serial.println(); }
  }
  analogWrite(aOut, aVal);
  analogWrite(bOut, bVal);
  analogWrite(cOut, cVal);  }

———————————–

By the way, yesterday I ran into an street installation made by Ted Southern in Dumbo. It is a sidewalk-attached interactive music maker ontrolled easily via an interface by the public. Basically the interface is just a box installed different tuners and sensors controlling two rows of speakers that have different sound quality from each other.  So people passing by can play with it at ease without any instruction or guide.  But the inconvenience about this project is that the artist has to screw and open the box to replace batteries (there are two 9 V)every few hours.

Dscn0105

Dscn0106

Dscn0107