My color mixer
http://vimeo.com/moogaloop.swf?clip_id=1856128&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1
my color mixer from maze on Vimeo.
Materials: Arduino, jumper wires, potentiometer, 9v battery, LEDs, resistors, DC power plug, tracing paper, scotch tape, fiberfill
Here is my code:
/*
*Color Mixer
*Tzumei M. Hsiao
*I modified the code from "Coffee-cup" color mixer on Arduino.cc
*/
// Analog pin settings
int potIn = 3; // the potentiometer connected to the analog pin 3
// Digital pin settings
int redLED = 9; // LEDs connected to digital pins 9, 10 and 11
int blueLED = 10; // (Connect cathodes to digital ground)
int greenLED = 11;
// Values
int potVal = 0; // the variable to store the input from the potentiometer
int redVal = 0; // the variable to store the value of red LED
int greenVal = 0; // the variable to store the value of green LED
int blueVal = 0; // the variable to store the value of blue LED
// Variables for comparing values between loops
int i = 0; // Loop counter
int wait = (1000); // Delay between most recent pot adjustment and output
int sens = 3; // Sensitivity threshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
void setup()
{
pinMode(redLED, OUTPUT); // sets the digital pins as output
pinMode(blueLED, OUTPUT);
pinMode(greenLED, OUTPUT);
Serial.begin(9600); // Open serial communication for reporting
}
void loop()
{
i += 1; // Count loop
potVal = analogRead(potIn); // read input pins, convert to 0-255 scale
if (potVal< 341)
{
potVal= (potVal* 3) / 4; //normalize to 0-255
redVal= 255-potVal;
greenVal= potVal;
blueVal= 1; //blue off
} //end of if
else if (potVal< 682)
{
potVal= ((potVal-341)*3) / 4; //normalize to 0-255
redVal= 1; //red off
greenVal= 255-potVal;
blueVal= potVal;
} //end of else if
else
{
potVal= ((potVal-682)*3)/ 4; //normalize to 0-255
redVal= potVal;
greenVal= 1; //green off
blueVal= 255-potVal;
} //end of else
analogWrite(redLED, redVal); // Send the new value to LEDs
analogWrite(blueLED, blueVal);
analogWrite(greenLED, greenVal);
if (i % wait == 0) // If enough time has passed…
{
if ( potVal > sens ) // If old and new values differ
// above sensitivity threshold
{
if (PRINT) // …and if the PRINT flag is set…
{
Serial.print("The value of potentiometer: "); // …then print the values.
Serial.print(potVal);
PRINT = 0;
}
}
else
{
PRINT = 1; // Re-set the flag
}
}
}
Reply