User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Playing with Pots

Submitted by bobacita on Sun, 09/21/2008 - 14:27

Assignment: Sensing: Potentiometers

Collaborators:

Assignment: Sensing: Potentiometers

Collaborators:

Description

Soldered wires onto potentiometers (pots) and connected pots in a circuit to control the RGB LEDs.

For the required portion of the assignment (a), opted to use 3 pots to control the brightness of 3 LEDs.

For the optional portion (b), revised the code to blink faster as the LEDs dim, and blink slower as the LEDS get brighter.  At a happy medium, with a cloth lantern diffuser, the setup looks like a disco ball!

 

Components

3 LEDs (red, blue, green)

3 potentiometers

3 220-ohm resistors

A cloth lantern diffuser

17 wires

Code

(a)

/*
* "Coffee-cup" Color Mixer:
* Code for mixing and reporting PWM-mediated color
* Assumes Arduino 0004 or higher, as it uses Serial.begin()-style communication
*
* Control 3 LEDs with 3 potentiometers
* If the LEDs are different colors, and are directed at diffusing surface (stuck in a
* a Ping-Pong ball, or placed in a paper coffee cup with a cut-out bottom and
* a white plastic lid), the colors will mix together.
*
* When you mix a color you like, stop adjusting the pots.
* The mix values that create that color will be reported via serial out.
*
* Standard colors for light mixing are Red, Green, and Blue, though you can mix
* with any three colors; Red + Blue + White would let you mix shades of red,
* blue, and purple (though no yellow, orange, green, or blue-green.)
*
* Put 220 Ohm resistors in line with pots, to prevent circuit from
* grounding out when the pots are at zero
*/

// Analog pin settings
int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2
int bIn = 1; // (Connect power to 5V and ground to analog ground)
int cIn = 2;

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

// 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;

analogWrite(aOut, aVal); // Send new values to LEDs
analogWrite(bOut, bVal);
analogWrite(cOut, cVal);

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);
}
}
}

(b)

/*
* Blink and Bright:
* Code for mixing and reporting PWM-mediated color
* Assumes Arduino 0004 or higher, as it uses Serial.begin()-style communication
*
* Control 3 LEDs with 3 potentiometers
* If the LEDs are different colors, and are directed at diffusing surface (stuck in a
* a Ping-Pong ball, or placed in a paper coffee cup with a cut-out bottom and
* a white plastic lid), the colors will mix together.
*
* When you mix a color you like, stop adjusting the pots.
* The mix values that create that color will be reported via serial out.
*
* Increasing the brightness of the LEDs will slow the blinking rate. As the LEDs
* dim, they will blink faster.
*
* Standard colors for light mixing are Red, Green, and Blue, though you can mix
* with any three colors; Red + Blue + White would let you mix shades of red,
* blue, and purple (though no yellow, orange, green, or blue-green.)
*
* Put 220 Ohm resistors in line with pots, to prevent circuit from
* grounding out when the pots are at zero
*/

// Analog pin settings
int aIn = 0; // Potentiometers connected to analog pins 0, 1, and 2
int bIn = 1; // (Connect power to 5V and ground to analog ground)
int cIn = 2;

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

// Sensor value at each pot
int aSens = 0;
int bSens = 0;
int cSens = 0;

// 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

aSens = analogRead(aIn);
bSens = analogRead(bIn);
cSens = analogRead(cIn);

aVal = aSens / 4; // read input pins, convert to 0-255 scale
bVal = bSens / 4;
cVal = cSens / 4;

analogWrite(aOut, aVal); // Send new brightness values to LEDs
digitalWrite(aOut, HIGH); // Blink with a delay of time <value read on the sensor>
delay(aSens);
digitalWrite(aOut, LOW);
delay(aSens);

analogWrite(bOut, bVal);
digitalWrite(bOut, HIGH);
delay(bSens);
digitalWrite(bOut, LOW);
delay(bSens);

analogWrite(cOut, cVal);
digitalWrite(cOut, HIGH);
delay(cSens);
digitalWrite(cOut, LOW);
delay(cSens);

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);
}
}
}


Photos attached

Videos can be seen at:

http://people.ischool.berkeley.edu/~carolc/MVI_2896.AVI

http://people.ischool.berkeley.edu/~carolc/MVI_2899.AVI

http://people.ischool.berkeley.edu/~carolc/MVI_2900.AVI

http://people.ischool.berkeley.edu/~carolc/MVI_2901.AVI