~~~~~~~~~~~~~~~~~~~~~~~~
DESCRIPTION
~~~~~~~~~~~~~~~~~~~~~~~~
For the visualization part I created a 7 color rainbow bar that can be controlled with a potentiometer, a FSR, and a photocell receptor to adjust the direction, transparency and size of the bar respectively. Playing with the FSR and photocell create some especially fun effects such as creating the appearance of depth as the rainbow ribbon appears to move towards or away from the user and by tapping hard enough on the FSR you can go fully transparent which allows for creating shorter bars or dots that are spaced out instead of being one solid rainbow.
For the mechanical FSR construction I used an old contacts case, a balloon, and some small bits of cardboard. I cut a hole in the case for the control wires to poke out through and put a few small cardboard circles under the FSR head so that it would have a flat surface to rest on. Then I crammed an un-inflated orange “Happy Birthday” balloon into the case on top of the FSR. With one more cardboard disc on top (to reduce the friction of the lid with the rubbery balloon) I placed the screw on cap back on. So now the FSR can be adjusted by loosening or tightening the cap. Because of the short threading there is a limited range of adjustment, so something like a soda bottle cap would be nice to try as well for increased control.
~~~~~~~~~~~~~~~~~~~~~~~~
COMPONENTS
~~~~~~~~~~~~~~~~~~~~~~~~
1- Arduino Uno
1 - Breadboard
1 - Potentiometer
1 - Photocell Receptor
1 - Force Sensitive Resistor
2 − 10k Ω Resistors
assorted wires
~~~~~~~~~~~~~~~~~~~~~~~~
ARDUINO CODE
~~~~~~~~~~~~~~~~~~~~~~~~
/** RAINBOW_OUT
* (Jordan Arnesen, October 2013)
*
* Sends out controller values to the computer
* for use in Rainbow_TUI program.
*
*/
// analog inputs
int potIn = 0; // POT input connected to pin 0
int fsrIn = 1; // FSR input connected to pin 1
int phoIn = 2; // PHO input connected to pin 2
// values
int potVal = 0; // variable to store value from POT
int fsrVal = 0; // variable to store value from FSR
int phoVal = 0; // variable to store value from PHO
void setup()
{
Serial.begin(9600); // open communication for Processing to read
}
void loop()
{
potVal = analogRead(potIn);
fsrVal = analogRead(fsrIn);
phoVal = analogRead(phoIn);
Serial.print(potVal);
Serial.print("P");
Serial.print(fsrVal);
Serial.print("F");
Serial.print(phoVal);
Serial.println("H");
}
~~~~~~~~~~~~~~~~~~~~~~~~
PROCESSING CODE
~~~~~~~~~~~~~~~~~~~~~~~~
/**
* Rainbowy_TUI
* (Jordan Arnesen, October 2013)
*
* Control the rainbow!
*
* Reads serial input from Arduino for:
* 1 Pot (controls direction),
* 1 FSR (controls transparency), and
* 1 Photocell (controls size).
* Additional keyboard controls:
* f - speeds up movement
* s - slows down movement
* spacebar - erase window
*
*/
import processing.serial.*;
Serial port;
String buf="";
int cr = 13; // ASCII return == 13
int lf = 10; // ASCII linefeed == 10
// INPUT VARIABLES
int potVal, fsrVal, phoVal;
//RAINBOW VARIABLES
float angle = 1; //angle to calculate direction - from POT
float xd; // x direction of travel
float yd; // y direction of travel
int sw = 1; //stroke width - from PHOTOCELL
int tr = 255; //transparency - from FSR
float sp = .02; //speed
float xp, yp; // current position coordinates
float pxp, pyp; // previous position coordinates
void setup() {
size(640, 640);
background(255);
port = new Serial(this, Serial.list()[0], 9600);
xp = width/2;
yp = height/2;
}
void draw() {
}
/* called whenever serial data arrives,
* retrieves serial data, prints updated values,
* updates display with new drawing info.
*/
void serialEvent(Serial p) {
int c = port.read();
/* this print statement will allow you to see whether or not Processing can "hear" anything that
Arduino is sending. It should print all the changing values of the FSR or Photocell in your circuit
If nothing is printing, you probably picked the wrong serial port.
*/
println(c); // prints the raw serial data
if (c != lf && c != cr && c != 80 && c != 70 && c != 72) {
buf += char(c);
}
if (c == 80) { // AASCI for "P"
potVal = int(buf);
angle = potVal/2.84; // set angle
println("potVal="+potVal);
println("angle="+angle);
buf = "";
}
if (c == 70) { // AASCI for "F"
fsrVal = int(buf);
tr = max(15-(fsrVal/20), 0); // set transparency
println("fsrVal="+fsrVal);
println("transparency="+tr);
buf = "";
}
if (c == 72) { // AASCI for "H"
phoVal = int(buf);
sw = (1024-phoVal)/34; // set stroke width
println("phoVal="+phoVal);
println("stroke="+sw);
buf = "";
}
if (c == lf) {
println("end of input");
buf = "";
}
//UPDATING THE VARIABLES
pxp = xp; // set previous coordinates
pyp = yp;
// recalculate direction of movement
if (angle < 91) { // quadrant 3, -x +y
xd = -(angle/90);
yd = 1 - abs(xd);
}
else if (angle < 181) { // quadrant 2, -x -y
xd = -(1 - abs(yd));
yd = -((angle-90)/90);
}
else if (angle < 271) { // quadrant 1, +x -y
xd = (angle-180)/90;
yd = -(1 - abs(xd));
}
else { // quadrant 4, +x +y
xd = 1 - abs(yd);
yd = (angle-270)/90;
}
// set new points
xp = (xp + ( sp * xd )) % (width + 3*sw + 1);
yp = (yp + ( sp * yd )) % (height + 1);
// Keep within screen boundaries
if (xp < 0 ) {
xp = xp + width;
pxp = xp -1;
}
if (yp < 0) {
yp = yp + height;
pyp = yp - 1;
}
strokeWeight(sw);
// DRAWING THE RAINBOW
stroke(220, 5, 0, tr); //red
line(xp-3*sw, yp, pxp-3*sw, pyp);
stroke(255, 132, 0, tr); // orange
line(xp-2*sw, yp, pxp-2*sw, pyp);
stroke(250, 230, 0, tr); // yellow
line(xp-sw, yp, pxp-sw, pyp);
stroke(10, 200, 0, tr); //green - CENTER COLOR
line(xp, yp, pxp, pyp);
stroke(35, 70, 250, tr); //blue
line(xp+sw, yp, pxp+sw, pyp);
stroke(0, 230, 240, tr); //indigo
line(xp+2*sw, yp, pxp+2*sw, pyp);
stroke(90, 0, 186, tr); //purple
line(xp+3*sw, yp, pxp+3*sw, pyp);
}
// extra keyboard controls
void keyPressed() {
if (key == ' ') {
background(255); // erase screen
}
else if (key == 'f') { // speed up
sp = min((sp + .2), 10) ;
}
else if (key == 's') { // slow down
sp = max((sp - .2), .1) ;
}
}
- Login to post comments