Description
Allows the user to control three color spectrums with three different pots.
Components Used
Arduino Diecimila
3 LEDS (1 red, 1 blue, 1 green)
3 resistors
3 potentiometers
various wires
Arduino Code
/*
* Color Mixer:
* Code for mixing and reporting PWM-mediated color
* Assumes Arduino 0004 or higher, as it uses Serial.begin()-style communication
*
* Control Three Color Spectrums with Three Pots
*
* This code allows you to control three color spectrums
* with three different pots.
* One thing to note is that all three pots should be set to zero
* at the beginning in order to have it work at prime form.
*
* One pot controls the red/blue spectrum, another the blue/green spectrum, and the third the green/red spectrum.
*
*
* Shawna Hein
* TUI, September 19 2007
*
*/
// Analog pin settings
int aIn = 1; // Potentiometers connected to analog pins 0, 1, and 2
int bIn = 2; // (Connect power to 5V and ground to analog ground)
int cIn = 3;
// Digital pin settings
int aOut = 10; // LEDs connected to digital pins 9, 10 and 11 //green
int bOut = 9; // (Connect cathodes to digital ground) //blue
int cOut = 11; //changed the order so that the pots are in "RGB" order on my desk. //red
// Values
int aVal = 0; // Variables to store the input from the potentiometers
int bVal = 0;
int cVal = 0;
// Variables for comparing values between loops
int i = 0; // Loop counter
int wait = (1000); // Delay between most recent pot adjustment and output
int checkSum = 0; // Aggregate pot values
int prevCheckSum = 0;
int sens = 3; // Sensitivity theshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(aOut, OUTPUT); // sets the digital pins as output
pinMode(bOut, OUTPUT);
pinMode(cOut, OUTPUT);
Serial.begin(9600); // Open serial communication for reporting
}
void loop()
{
i += 1; // Count loop
aVal = analogRead(aIn) / 4; // read input pins, convert to 0-255 scale
bVal = analogRead(bIn) / 4;
cVal = analogRead(cIn) / 4;
if(aVal==0 && cVal==0 && bVal!=0){ //if the user is moving the right-most pot on my board (analog pin 2)
aVal=0; //green //set the LEDs to a red/blue spectrum (green to 0, red to steady value)
cVal=30; //red
Serial.print("Moving through the red/blue Spectrum");
}
else if(bVal==0 && cVal==0 && aVal!=0){ //if the user is moving the middle pot on my board (analog pin 1)
cVal=0; //red //set the LEDs to a blue/green spectrum, red to 0, blue to steady value
bVal=50; //blue
Serial.print("Moving through the blue/green Spectrum");
}
else if(aVal==0 && bVal==0 && cVal!=0){ //if the user is moving the left-most pot on my board (analog pin 3)
bVal=0; //blue //set the LEDs to a green/red spectrum, blue to 0, green to steady value
aVal=50; //green
Serial.print("Moving through the green/red Spectrum");
}
analogWrite(aOut, aVal); //green// Send new values to LEDs
analogWrite(bOut, bVal); //blue
analogWrite(cOut, cVal); //red
if (i % wait == 0) // If enough time has passed...
{
checkSum = aVal+bVal+cVal; // ...add up the 3 values.
if ( abs(checkSum - prevCheckSum) > sens ) // If old and new values differ
// above sensitivity threshold
{
if (PRINT) // ...and if the PRINT flag is set...
{
Serial.print("A: "); // ...then print the values.
Serial.print(aVal);
Serial.print("\t");
Serial.print("B: ");
Serial.print(bVal);
Serial.print("\t");
Serial.print("C: ");
Serial.println(cVal);
PRINT = 0;
}
}
else
{
PRINT = 1; // Re-set the flag
}
prevCheckSum = checkSum; // Update the values
if (DEBUG) // If we want debugging output as well...
{
Serial.print(checkSum);
Serial.print("<=>");
Serial.print(prevCheckSum);
Serial.print("\tPrint: ");
Serial.println(PRINT);
}
}
}
Item
3Pots Shell
3Pots Red/Blue
3Pots Blue/Green
3Pots Green/Red