User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Color mixer

Submitted by RyanKaufman on Thu, 09/25/2008 - 00:01

Assignment: Sensing: Potentiometers

Collaborators:

Description:

In this lab, I used one pontentiometer to control the rate and blue LED's intensity. The other pot. was used to cycle back in forth between red and green. I coded the loop to give 4 different functions of the color inputs from the potentiometers.

Components Used:

* (3) LEDs: red, green, blue
* (3) 220 ohm resitors
* (2) potentiometers
* (1) Arduino board
* (1) breadboard
* Diffuser

Arduino Code:
/*
* One of the potentiometers controls the rate of color change and the other controls
* the mix of colors for a fun effect. The blue intensity parallels the rate.
*/
int potPin1 = 1; // select the input pin for the rate potentiometer
int potPin2 = 2; // select the input pin for the color potentiometer
int rPin = 9; // Red LED output on pin 9
int gPin = 10; // Green LED output on pin 10
int bPin = 11; // Blue LED output on pin 11
int colorval = 0; // variable to store the value coming from the color potentiometer
int rateval = 0; // variable to store the value coming from the rate potentiometer
int ratedelay = 0; // variable to store the delay time
int rVal, bVal, gVal;

void setup() {
pinMode(rPin, OUTPUT); // Each assigned LED pin becomes an output
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
}
void loop() {
rateval = analogRead(potPin1); // read the value from potentiometer
ratedelay = (1024-rateval)/2;
colorval = analogRead(potPin2); // read the value from the sensor, between 0 - 1024
colorval = (int)(colorval/4);
gVal = colorval; //green is at max when brightval is 255 and min when 0
rVal = (255 - colorval); //red is at max when brightval is 0 and min when 255
bVal = (colorval - rateval); //blue value is the green value-the rate value

analogWrite(rPin, rVal);
analogWrite(gPin, gVal/1.5);
analogWrite(bPin, bVal*1.2);
delay(ratedelay); // stop the program for some time
analogWrite(rPin, 0);
analogWrite(gPin, 0);
analogWrite(bPin, 0);
delay(ratedelay/1.2); // stop the program for some time
analogWrite(rPin, rVal);
analogWrite(gPin, gVal*1.5);
analogWrite(bPin, bVal/.9);
delay(ratedelay /1.5); // stop the program for some time
analogWrite(rPin, 0);
analogWrite(gPin, 0);
analogWrite(bPin, 0);
delay(ratedelay/2); // stop the program for some time
analogWrite(rPin, rVal);
analogWrite(gPin, gVal/2);
analogWrite(bPin, bVal*1);
delay(ratedelay/1.7); // stop the program for some time
analogWrite(rPin, 0);
analogWrite(gPin, 0);
analogWrite(bPin, 0);
delay(ratedelay/1.9); // stop the program for some time
analogWrite(rPin, rVal);
analogWrite(gPin, gVal/.5);
analogWrite(bPin, bVal*.7);
delay(ratedelay/2.2); // stop the program for some time
analogWrite(rPin, 0);
analogWrite(gPin, 0);
analogWrite(bPin, 0);
delay(ratedelay/2.5); // stop the program for some time

}