Tri-Color Pendulums: Jason Yore Making Things Interactive Carnegie Mellon University Fall 2010
Tri-Color Pendulums: Jason Yore Making Things Interactive Carnegie Mellon University Fall 2010
Tri-Color Pendulums: Jason Yore Making Things Interactive Carnegie Mellon University Fall 2010
Jason Yore
Making Things Interactive
Carnegie Mellon University
Fall 2010
t
Materials
Electronic:
Arduino Mega
breadboard
3x: 2-Axis Joystick: Adafruit (Parallax ID: 245)
3x: RGB LED: Sparkfun (sku: COM-00105 )
3x: 330 Ohm resistor (for blue and green LEDs)
6x:150 Ohm resistor (for red LEDs)
A lot of hookup wire
Solder (and soldering iron)
Structural:
MDF Sheet (substitute ceiling)
Wood beams (support legs)
Acrylic Mounts (for Joysticks)
Hot Glue
Epoxy
3x: 1 inch diameter x 2 foot PVC pipe
3x: light bulbs
6x: 1 inch diameter coupling (to interface with bulbs and joysticks)
Construction
Take 3 lightbulbs and carefully hollow them out, removing the filament and
other guts inside. Spray them white so the light in them will be diffuse..
Use epoxy to attach each of them to the inside of a pvc couple. This creates a
removable light housing.
take the thumbpads off of the joysticks and use epoxy to attach each of them
leveled to the inside of a pvc couple as well. This allows for easy disassembly,
storage, and transportation. Now drill a bout a 1/4 inch hole in these coupled
to allow for the wires to the LEDs.
Solder the LEDs’ leads to resistors and then to wires at least 3 feet in length.
Run the wires through the pvc pipe so the led hangs below the pipe by an inch
or two and attach the bulb,couple over it. Run the wires up and through the
hole at the top couple that is attached to the thumb pad.
Take a piece of MDF or similar material and cut three holes for the joysticks to
hang through. Space them along points of an equilateral triangle with sides
of about 28 or so inches You can cut these exact or leave room for a custom
mount like I made by laser cutting acrylic to fit the joysticks. Hot glue the
joysticks to the mounts and the mounts to the holes. drill 1/4 inch holes next
to each mount for the LEDs’ wires to continue through.
Epoxy the pendulum assemblies to the joysticks, reattaching the thumb pads.
Frtizing
Schematic
Code
//Since I know I will only be making 3 lights, I found it easier to list out
//my code for each instead of creating object instances. It is more straightforward
// and easier to troubleshoot this way.
// I used an arduino mega 2560 which gives me enough PWM pins that the standard arduino doesn’t
int gRed = 6;
int gGreen = 7;
int gBlue = 8;
int valRX;
int valRY;
int valGX;
int valGY;
int valBX;
int valBY;
int curRX;
int curRY;
int curGX;
int curGY;
int curBX;
int curBY;
int RXL;
int RXH;
int RYL;
int RYH;
int GXL;
int GXH;
int GYL;
int GYH;
int BXL;
int BXH;
int BYL;
int BYH;
int RGdist;
int GBdist;
int BRdist;
void setup()
{
Serial.begin(9600);
pinMode(potRX, INPUT);
pinMode(potRY, INPUT);
pinMode(potGX, INPUT);
pinMode(potGY, INPUT);
pinMode(potBX, INPUT);
pinMode(potBY, INPUT);
pinMode(rRed, OUTPUT);
pinMode(rGreen, OUTPUT);
pinMode(rBlue, OUTPUT);
pinMode(gRed, OUTPUT);
pinMode(gGreen, OUTPUT);
pinMode(gBlue, OUTPUT);
pinMode(bRed, OUTPUT);
pinMode(bGreen, OUTPUT);
pinMode(bBlue, OUTPUT);
//initial values before calibration
RXL = analogRead(potRX);
RXH = analogRead(potRX);
RYL = analogRead(potRY);
RYH = analogRead(potRY);
GXL = analogRead(potGX);
GXH = analogRead(potGX);
GYL = analogRead(potGY);
GYH = analogRead(potGY);
BXL = analogRead(potGX);
BXH = analogRead(potBX);
BYL = analogRead(potBY);
BYH = analogRead(potBY);
void loop()
{
// calibration: set new highs and lows for pot values X-axis and Y-axis
valRX=(map(curRX, RXL, RXH, 255, 0) -128 + rBaseX); //-128 sets center potentiometer value to ~0 HERE’S THE PROBLEM
valRY=(map(curRY, RYL, RYH, 255, 0) -128 + rBaseY); // “Base” variable sets each potentiometer to its “grided” x, y location
// map to 0 255 to align match up with coordinates and brightness values
valGX=(map(curGX, GXL, GXH, 255, 0) -128 + gBaseX); //x and y are reversed from y since it is inverted
valGY=(map(curGY, GYL, GYH, 255, 0) -128 + gBaseY);
valBX=(map(curBX, BXL, BXH, 255, 0) -128 + bBaseX); //CONSIDER subtracting “resting” x and y to shift and get 0 and not -3 etc
valBY=(map(curBY, BYL, BYH, 255, 0) -128 + bBaseY);
//determine distances between each light relative to the other two ****ITS PROBABLY THE LINE BELOW v
RGdist = constrain(sqrt( pow((valRX - valGX), 2) + pow((valRY - valGY), 2)), 0, 255); //distance formula: yields distance between 0
and 255
GBdist = constrain(sqrt( pow((valGX - valBX), 2) + pow((valGY - valBY), 2)), 0, 255);
BRdist = constrain(sqrt( pow((valBX - valRX), 2) + pow((valBY - valRY), 2)), 0, 255);
rG = constrain((255-RGdist), 0, 255); // subtract from 255 because we want closer to be brighter, not more dim
rB = constrain((255-BRdist), 0, 255); // ex No distance (0) = full (255) brightness. Full distance (255) = minimum (0) brightness
bR = constrain((255-BRdist), 0, 255);
bG = constrain((255-GBdist), 0, 255);
/////////////////////////////////////////////OUTPUT/////////////////////////////////////////////
// Now to write it all to each light’s three LED’s
// Serial.print(RGdist);
// Serial.print(“ “);
// Serial.print(GBdist);
// Serial.print(“ “);
// Serial.print(BRdist);
// Serial.println(“ “);
Serial.print(valRX);
Serial.print(“ “);
Serial.println(valRY);