Jennifer Dopazo - blog -

Recent News

Archives

My Flickr

October 6, 2008 @ 8:32 pm

Color Mixer


Color Mixer from Jennifer Dopazo on Vimeo.

/*
* This code has been modified from the Coffe Cup Color Mixer
* at http://arduino.cc/en/Tutorial/LEDColorMixerWith3Potentiometers
*/

// Setting up the analog pin with the potentiometer
int AnalogPot = 3; // potentiometer connected to pin 3

// Setting up the digital pins with the LEDs
int redLED = 9; // red LED connected to pin 9
int greenLED = 10; // green LED connected to pin 10
int yellowLED = 11; // yellow LED connected to pin 11

// Initial 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 yellowVal = 0; // the variable to store the value of yellow 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(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
Serial.begin(9600); // Open serial communication for reporting
}

void loop()
{
i += 1; // Count loop

potVal = analogRead(AnalogPot); // read input pins, convert to 0-255 scale

if (potVal< 341)
{
potVal= (potVal* 3) / 4; //normalize to 0-255
redVal= 255-potVal;
greenVal= potVal;
yellowVal= 1; //yellow off
} //end of if
else if (potVal< 682)
{
potVal= ((potVal-341)*3) / 4; //normalize to 0-255
redVal= 1; //red off
greenVal= 255-potVal;
yellowVal= potVal;
} //end of else if
else
{
potVal= ((potVal-682)*3)/ 4; //normalize to 0-255
redVal= potVal;
greenVal= 1; //green off
yellowVal= 255-potVal;
} //end of else

analogWrite(redLED, redVal); // Send the new value to LEDs
analogWrite(greenLED, yellowVal);
analogWrite(yellowLED, 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
}

}
}

Filed under Physical Computing

Leave a Comment

Hello!

Photobucket

Links

Categories