I Hand a Dream: Project Showcase

IMG_5102Whew! What a show! I Hand a Dream all came together nicely in this year’s Interactive Media Show, Unexpected Token! So, pretty much everything fell into place. It’s really nice that people really liked what I did. Here’s a video of me trying out the installation. Check it out!

 

Here’s what one of the people who interacted with the installation had to say:

 

 

Here’s another one:

 

 

One last one:

 

 

That’s it for now! Happy holidays!

 

I Hand a Dream: Code (Processing+Arduino)

The most exciting part of them all!

The code!

So in order to build this project, the code isn’t actually very difficult. We just need to make sure that Arduino talks to Processing properly, and that the writing is right in the Arduino so that Processing gets to react and display the right things.

In terms of the Capacitive Sensing, I guess it makes sense to explain what it is exactly. Capacitive sensing is effectively just measuring the time for a charge to get back. What happens is that you ask the Arduino to send out a charge, and then start timing, and then depending on the resistance of an exposed end, wait for the return of the change, and then measure the time since. This tells you if somebody is touching the object or not: if it takes longer for the charge to return, then somebody is in fact touching the object.

For my Arduino code, it was pretty straightforward. I imported the capacitive sensor library, then I began serial connection, and then I sent a specific kind of data to the serial port depending on the natural inputs.

//FINAL PROJECT CODE (Arduino)
//Patrick Wee

//Include the Capacitive Sensor Library
#include <CapacitiveSensor.h>

//Tell Arduino these are ports on the board I am going to use for output and then input back in of the charge
CapacitiveSensor cs_3_2 = CapacitiveSensor(3,2);
CapacitiveSensor cs_5_4 = CapacitiveSensor(5,4);
CapacitiveSensor cs_7_6 = CapacitiveSensor(7,6); 
CapacitiveSensor cs_10_9 = CapacitiveSensor(10,9); 
CapacitiveSensor cs_12_11 = CapacitiveSensor(12,11); 

void setup(){
 //Let the communication begin!
 Serial.begin(9600);
 cs_3_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
}

void loop() 
{
 //millios() starts counting! Total takes note of the time! Note that this time updates every draw loop, and that every draw loop is run quite a lot of times per second.
 long start = millis();
 long total1 = cs_3_2.capacitiveSensor(30);
 long total2 = cs_5_4.capacitiveSensor(30);
 long total3 = cs_7_6.capacitiveSensor(30);
 long total4 = cs_10_9.capacitiveSensor(30);
 long total5 = cs_12_11.capacitiveSensor(30);
 
 //Send these to the serial for Processing depending on the total.
 if(total1>200){
 Serial.println('A');
 }else{
 Serial.println('B');
 }
 
 if(total2>1000){
 Serial.println('C');
 }else{
 Serial.println('D');
 }
 
 if(total3>1000){
 Serial.println('E');
 }else{
 Serial.println('F');
 }
 
 if(total4>1000){
 Serial.println('G');
 }else{
 Serial.println('H');
 }
 
 if(total5>1000){
 Serial.println('I');
 }else{
 Serial.println('J');
 }
 

 
//Code for Debugging!
 //Serial.print(millis() - start); // check on performance in milliseconds
 //Serial.print("\t"); // tab character for debug windown spacing

// Serial.print(total1); // print sensor output 1
// Serial.print("\t");
// Serial.print(total2); // print sensor output 2
// Serial.print("\t");
// Serial.print(total3); // print sensor output 3
// Serial.print("\t");
// Serial.print(total4); // print sensor output 4
// Serial.print("\t");
// Serial.println(total5); // print sensor output 5

 delay(1); // arbitrary delay to limit data to serial port 
}

As for the Processing code, it wasn’t also very complicated. Here’s how I wrote it:

//FINAL PROJECT CODE (Processing)
//Patrick Wee

//Import Libraries
import processing.serial.*;
import ddf.minim.*;

//Delcaring Objects for Audio Related Interactions
Minim minim;
AudioPlayer nafi;
AudioPlayer rita;
AudioPlayer girri;
AudioPlayer laura;
AudioPlayer sebastian;
Serial myPort; // The serial port

//Declared a Boolean for Use Later
boolean drawMe=false;

void setup() {
 //Set some basic stuff for the sketch.
 size(500, 500);
 background(0);
 
 //Read from the Serial
 myPort = new Serial(this, Serial.list()[3], 9600);
 myPort.bufferUntil('\n');
 
 
 //Load the Minim Files
 minim = new Minim(this); 
 nafi = minim.loadFile("Nafi.aiff");
 rita = minim.loadFile("Rita.aiff");
 girri = minim.loadFile("Girri.aiff");
 laura = minim.loadFile("Laura.aiff");
 sebastian = minim.loadFile("Sebastian.aiff");
}

void draw() { 
 //This alerts me if something is being detected.
 if (drawMe) {
 ellipse(250, 250, 50, 50);
 }else{
 background(0);
 }
}

void serialEvent(Serial myPort) {
 //String from Arduino is read and adjusted for Processing!
 String inString=myPort.readStringUntil('\n');
 if (inString != null) {
 inString = trim(inString); 

 //Set the different sounds you want to put for every input received from Arduino.

 if (inString.equals("A")) {
 drawMe=true;
 rita.play();
 rita.rewind();
 } else {
 drawMe=false;
 }
 
 if (inString.equals("C")) {
 drawMe=true;
 girri.play();
 girri.rewind();
 } else {
 drawMe=false;
 }
 
 if (inString.equals("E")) {
 drawMe=true;
 nafi.play();
 nafi.rewind();
 } else {
 drawMe=false;
 }
 
 if (inString.equals("G")) {
 drawMe=true;
 sebastian.play();
 sebastian.rewind();
 } else {
 drawMe=false;
 }
 
 if (inString.equals("I")) {
 drawMe=true;
 laura.play();
 laura.rewind();
 } else {
 drawMe=false;
 }
}
}

So here is the code I used! It’s nicely commented, so it shouldn’t be too difficult to understand. So if you plan to play with this remember, to run Arduino first. You can also uncomment the print function of the totals so you can find out what’s happening, if there’s anything wrong, and also to find the threshold for the resistance.

So that’s it! Have fun with the code!

Final Project Blueprint: I Have a Dream

In light of the recent events in Ferguson, the issue of race has once been the hot topic of discussion. The fact that a person was shot just because of preconceived notions about his race is something very alarming.

Martin Luther King’s “I Have a Dream” speech responds to this issue of race over fifty years ago. In it, he decries the racial injustice of his time: the struggles a Black American has to face in the South just because of his race, and the futility of freedom that Black Americans experience in the North where they don’t really feel that they’re respectably included into society.

With the recent events in Ferguson and beyond, now, in 2014, how do people respond to this issue of race? In a broader context, how have people’s dreams for the world changed? What are the world’s dreams for tomorrow? How similar or different are they from Martin Luther King’s? In short, Martin had a dream. What’s yours?

With this in mind, I’m going to create an installation where there would be pictures of the youth with their hands outstretched. When someone touches the subject’s hand, a sound clip of that subject’s response to “I have a dream that…” will play. Viewers have the ability to touch multiple subject’s hands, so that a symphony of dreams would be played at the same time.

On the more technical side, this sensing would be done through Capacitive Touch in Arduino, and then through the serial port, transmitted to Processing for the playing of the sound clips. Photographs of the subjects as well as voice clips of the subjects must also be taken. Given these requirements, I guess the three main chunks of the implementation include: photography+sound, arduino+processing and wiring+connecting.

The hope of this installation is to allow people to think about how far we’ve really reached when it comes to the idea of injustice, racial or otherwise. Have we really moved on at all? What the youth of today dreams about is a representation of what the world today is still lacking in, and still need filling in, and so it’s a good way to see what kind of world do we also want to collectively envision and work towards.

Some challenges I think I may face include the capacitive sense not cooperating, as well as the different resistances of different people. There’s also a possible issue with regards to how people will know to touch the hands of the subjects pictured. Hopefully, these can be resolved along the way.

So, that’s it for now. I really wanted to make this project something meaningful, and I hope that through this simple project, I will be able to get more people to think about where we are today and where we want to be tomorrow.

 

Arduino Controls Processing

I’ve always loved Peanut Butter and Jelly sandwiches. I just love how the roughness of the peanut butter plays with the smoothness of the jelly. Now, Arduino is going to play with Processing! Yay!

So, basically, to make the two speak to each other, what we’re going to do is we’re going to make the two communicate through the serial port. Arduino will be taking inputs from the world, then sending messages to Processing, and then Processing will be listening for these messages, and then doing something with the messages it receives. So what I decided to do was to use a potentiometer(the knob) to control the colors in Processing.

Arduino already has the serial built in, but for processing you’ll have to import a library to do the work for you. Again, it’s not that hard. I’ve commented out the code nicely so it’s easy to understand. But basically, it’s what I’ve mentioned above. Before we get to the code, here’s a really cool video demonstrating the interaction!

Here’s the Arduino Code!

//ARDUINO CODE
void setup(){
  //Start communications!
  Serial.begin(9600);
}

void loop(){
  //Send the input from the potentiometer,
  //Divide by 4 so the number is manageable!
  Serial.write(analogRead(A0)/4);
  delay(1);

}

Here’s the Processing Code!

//PROCESSING CODE
//Import the Serial Library
import processing.serial.*;

//Instantiate Serial
Serial myPort;

//Instantiate the image
PImage logo;

int bgcolor=0;

void setup(){
  //Load Image and set the width/height of canvas to
  //the width and height of the image
  colorMode(HSB,255);
  logo=loadImage("http://arduino.cc/logo.png");
  size(logo.width,logo.height);

  //This helps you decide where your Arduino is!
  println("Available serial ports!");
  println(Serial.list());

  //Once you find out, let's chat!
  myPort=new Serial(this,Serial.list()[3],9600);
}

//Set background color to the info if there is info at all.
void draw(){
  if(myPort.available()>0){
    bgcolor=myPort.read();
    println(bgcolor);
  }
  background(bgcolor,255,255);
  image(logo,0,0);
}

So there it is! I was able to connect Arduino to Processing, and in the process, make Arduino control processing! But what about the reverse? For my next project, I’ll try working on the reverse! But, for now, it’s time to have some PB&J Sandwiches! Yehey!

Pearl: Discover Yourself (through Art)–A Drawing App

Screen Shot 2014-09-27 at 12.25.32 PM

I’ve always been fond of drawing apps. I remember the first time I ever opened up paint. Life was never the same again. Somehow, through the pixels of colors I was able to discover myself. I would draw random shapes and sizes, and they would end up nicely on the screen. From paint, I’ve moved on to other drawing programs, and today, I work on paper by Fifty Three.

So, a lot of the inspiration of this project which I called PEARL, comes from those childhood memories of drawing as a way of discovering myself. Through the Processing platform, I coded this drawing app that you could run on your computer. It has 5 main functions:

  • Pencil tool
  • Pen tool
  • Marker Tool
  • Paint Tool
  • Eraser Tool

You can also create a new white canvas as well as choose a random color for your this canvas. There are also cool surprises with this program! Before I show you some of the more technical design choices I made, here are some of the things I was able to create!

First of all, is the Logo! I created the image part of the logo using the program I wrote! How cool is that?

Screen Shot 2014-09-27 at 12.15.37 PM

Other than that, you can also other types of art! Here are some examples:

Screen Shot 2014-09-27 at 12.21.09 PM

The lizards swirls is what I call this piece! It’s pretty cool huh? Here’s another awesome one!Screen Shot 2014-09-27 at 12.09.07 PM

I call this one floors. But that’s just me. Anyway, it’s cool! And here’s my last piece. It’s called big man.

Screen Shot 2014-09-27 at 1.10.30 PM

It symbolizes big in Chinese. However, the word big in itself is just a man with arms spread out wide open. So, here’s the big man.

So with these awesome designs, I’ll get a little bit more technical, and explain the different things the program can do.

The Canvas

The most basic is how to get a white canvas. At the start of the set-up the canvas is already set to white, but you can also change it to a random colored background. To change the canvas back to white again, all you need to do is to just do a regular click. To change to a random colored background color, you have to do a right click.

So for example, this design is made on a white canvas.

Screen Shot 2014-09-27 at 1.18.55 PM

 

This one is made on a green canvas.

 

Screen Shot 2014-09-27 at 1.18.32 PM

Getting Around

When the program starts up, you can hover around your canvas and nothing will happen. With the keyboard buttons that you will learn below, you will be able to use various tools(pens, markers, paint). To stop any of the tools, all you have to hit is the ENTER key.

 

The Pencil

One of the most basic functions I included is the pencil. It is just a simple black line with a pencil like feel due to the transparency. To access the pencil, simply hit the p button.

Screen Shot 2014-09-27 at 1.17.32 PM

The Pen

The second thing I worked on was the pens. This is pretty much just like the pencil but will a full blast of color. One of the challenges I had with color was that I had to communicate to people a palette of colors using a keyboard. So, what I did to do that easily is to an entire row of the keyboard, firstly, and secondly, use the colors of the rainbow. This way, even if there aren’t any visual cues, people mostly know the colors of the rainbow, so from there, they can confidently access the keys, given the limitations of Processing (at least for now!)

So, for example, to access the pen, you will have to hit 1 for black, and then 2, 3,4,5,6, 7 and 8 represent the main rainbow colors (red, orange, yellow, green, blue, indigo, pink*) I replaced violet with pink since indigo is already around! And then there’s a secret with the last button which I will discuss later. So to access any of the colors, you just have to hit one of the numbers and you can start drawing with the colors. Here’s a sample with the pen tool! Once you would like to stop any of the pens, hit the ENTER key.

Screen Shot 2014-09-27 at 12.52.52 PM
The Marker

So, the next tool up is the heart and soul of Pearl. It’s the marker tool. I wanted this to the heart and soul of the program. So, to do that, I wanted the lines to feel as naturally nice as possible. To be able to do this, I used easing all throughout the code. What this means is that it considers your movement as it decides the weight of the lines. As a result, it gives this very artistic dash-like design. (You can see how I do this in the code below!)

Just like the pen, I also used the rainbow and used an entire row of a keyboard. So, I used the qwerty row, where q is black, wertyui are all the colors of the rainbow*. (Again, I replaced violet with pink since indigo is already around!) And then, o is a special character again. Once you would like to stop any of the markers, hit the ENTER key.

Screen Shot 2014-09-27 at 12.53.20 PM

 

The Paint

So, the coolest tool up in my opinion is the paint tool. It’s this thick line that can paint through the different shapes that you make!

Just like the pen, I also used the rainbow and used an entire row of a keyboard. So, I used the asdf row, where a is black, sdfghjk are all the colors of the rainbow*. (Again, I replaced violet with pink since indigo is already around!) And then, l is a special character again. Once you would like to stop the paint brush, hit the ENTER key.

 

Screen Shot 2014-09-27 at 12.54.04 PM

 

The Eraser

The final tool is the eraser, where you can erase things if you do not like it. It’s pretty clean, and whites out whatever you don’t want! To access the Eraser, simply enter the SPACE key. Again, once you would like to stop the Eraser, hit the ENTER key.

And one last thing–The Secret Buttons!

The last button of every row which I haven’t mentioned to you yet is actually a secret button! It’s called the random color button! What it does is that it gives you a pen, marker and a paint brush in a random color each time you hit it. So, watch out when you hit the 9,o, and l keys! Let the colors explode! So for example, this one design below was made using the secret button for markers!

Screen Shot 2014-09-27 at 12.12.12 PM

So that’s it for now. It’s a pretty cool thing, huh? If you’re on the techie side and you’d like to know how I implemented the program, here’s the source code in Java. If you want to know how to run and play around, shoot me a comment, and we’ll work something out!


float x;
float y;
float px;
float py;
char determiner;
float easing=0.05;

//This controls the stroke of the pen and pencil.
int pen=2;
int paint=30;
int eraser=50;

//This controls the transparency of the tools.
int paintt=50;
int pent=230;
int markert=255;

void setup(){
  size(800,800);
  background(255,255,255);
  smooth();
  noStroke();
}

void draw(){
 float targetX=mouseX;
 x+=(targetX-x)*easing;
 float targetY=mouseY;
 y+=(targetY-y)*easing;
 float weight=dist(x,y,px,py);
 
 
 if (determiner=='e'){
   strokeWeight(weight);
 }else if(determiner=='p'){
   strokeWeight(pen);
 }else if(determiner=='b'){
   strokeWeight(paint);
 }else if(determiner=='c'){
   strokeWeight(eraser);
 }
 
 
 line(x,y,px,py);
 py=y;
 px=x;

 
}

void keyPressed(){
  println(key+" key was pressed!");

  if (keyPressed){
    
    //Hovering Around the Screen
    if(key==ENTER){
      noStroke();
    }
    
    //PEN
    
    //black
    else if (key=='1'){
        stroke(0,0,0,pent);
        determiner='p';
    }
    
    //red
    else if (key=='2'){
        stroke(#FF0000,pent);
        determiner='p';
    } 

    
    //orange
    else if (key=='3'){
        stroke(#FF7F00,pent);
        determiner='p';
    }
    
    //yellow
    else if (key=='4'){
        stroke(#FFFF00,pent);
        determiner='p';
    }
    
    //green
    else if (key=='5'){
        stroke(#00FF00,230);
        determiner='p';
    }
    
    //blue
    else if (key=='6'){
        stroke(#0000FF,pent);
        determiner='p';
    }
    
    
    //violet
    else if (key=='7'){
        stroke(#8B00FF,pent);
        determiner='p';
    }
    
    //pink
    else if (key=='8'){
        stroke(#FF33E4,markert);
        determiner='e';
    }
    
 
    //random
    else if (key=='9'){
        stroke(random(255),random(255),random(255),pent);
        determiner='p';
    }
    
    
    
    
    //MARKER
    
    //black
    else if (key=='q'){
        stroke(0,0,0,markert);
        determiner='e';
    }
    
    //red
    else if (key=='w'){
        stroke(#FF0000,markert);
        determiner='e';
    }
    
    //orange
    else if (key=='e'){
        stroke(#FF7F00,markert);
        determiner='e';
    }
    
    //yellow
    else if (key=='r'){
        stroke(#FFFF00,markert);
        determiner='e';
    }
    
    //green
    else if (key=='t'){
        stroke(#00FF00,markert);
        determiner='e';
    }
    
    //blue
    else if (key=='y'){
        stroke(#0000FF,markert);
        determiner='e';
    }
    
    //violet
    else if (key=='u'){
        stroke(#8B00FF,markert);
        determiner='e';
    }
    
    //pink
    else if (key=='i'){
        stroke(#FF33E4,markert);
        determiner='e';
    }
    
    //random
    else if (key=='o'){
        stroke(random(255),random(255),random(255),markert);
        determiner='e';
    }
    
    
    
    //PAINT
    
    //black
    
    else if (key=='a'){
        stroke(0,0,0,paintt);
        determiner='b';
    }
    
    //red
    else if (key=='s'){
        stroke(#FF0000,paintt);
        determiner='b';
    }
    
    //orange
    else if (key=='d'){
        stroke(#FF7F00,paintt);
        determiner='b';
    }
    
    //yellow
    else if (key=='f'){
        stroke(#FFFF00,paintt);
        determiner='b';
    }
    
    //green
    else if (key=='g'){
        stroke(#00FF00,paintt);
        determiner='b';
    }
    
    //blue
    else if (key=='h'){
        stroke(#0000FF,paintt);
        determiner='b';
    }
   
    
    //violet
    else if (key=='j'){
        stroke(#8B00FF,paintt);
        determiner='b';
    }
    
    //pink
    else if (key=='k'){
        stroke(#FF33E4,paintt);
        determiner='b';
    }
    
    //random
    else if (key=='l'){
        stroke(random(255),random(255),random(255),paintt);
        determiner='b';
    }
    
    
    
   //eraser
   else if (key==' '){
        stroke(255,255,255);
        determiner='c';
   }

   
   
   //Pencil
   else if (key=='p'){
        stroke(0,0,0,100);
        determiner='p';
   }
}
}

void mousePressed(){
   if (mouseButton==LEFT){
     background(255,255,255);
   }else if(mouseButton==RIGHT){
     background(random(255),random(255),random(255));
   }
}

Hope you enjoyed!

 

 

Fluorescent Eggs

Say hi to the Fluorescent Egg!

Say hi to the Fluorescent Egg!

Yes, fluorescent eggs do sound peculiar, but in Introduction to Interactive Media (IIM) class, that’s what we pretty much did. As you can see above, the image looks like a hard-boiled egg sliced in half, with the yolk sticking out. How the fluorescent part came about was when one of my classmates mentioned in class how the egg has a peculiar yellow color. And walla, fluorescent egg it became.

But honestly, what’s cooler than the fluorescent egg, is the fact that the image above was created with no mouse clicks (well, technically, no mouse clicks) at all. All that was used was code, hard-code to set the shapes, the colors, the frames! Can you believe that? Here’s proof:

Screen Shot 2014-09-15 at 9.34.43 PM

So, the software we were actually using for this project is known as Processing. I’m not that good with definitions so let the program define itself: “Processing is a programming language, development environment, and online community.” What’s interesting is that this environment was made just in 2001 and developed by people from around the world ever since. Now, we’re using it in class for development purposes!

However, apart from just fluorescent eggs, you can create really cool things with the program. For example, I came up with this abstract drawing using just a few lines of wonderful code! (Forgive me for my comments in the code!)

Screen Shot 2014-09-15 at 9.33.40 PM

And there’s also the solitaire success like-state, where you can move a certain shape around and the shape gets printed along your path, much like when you finish Solitaire!

Screen Shot 2014-09-15 at 9.35.40 PM

And then of course, there are really cool ones like this revolving sun, earth and mercury(if I’m not mistaken) image where all rotate around the sun (with the sun rotating itself!) Of course, I did that, right?

Screen Shot 2014-09-15 at 9.36.12 PM

Nah, it’s just fluorescent eggs for me for now.

Hey, but let’s see what I can do at the end of the semester!