Skip navigation

… code

In our project, the code is based in the excange of sounds related to the physical behaviour of the objects.
For this reason we used both Processing code and Arduino code. We also created the comunication between Processing and Arduino.

f

PROCESSING CODE

In first we import the minim library in Processing that permit to manage sounds.

import ddf.minim.*;

Than we wrote a program to record a sound, stop recording, and play another sound. For each action (record, play, stop..) we chose a letter as a key. For example we put ‘p’ for the play command. Using those letters we could communicate with Arduino.

void dataReceived() {
case ‘p’: // PLAY
messageWaiting = false;// stop dropping the string
if (player == null){
// create a player and load the file player = minim.loadFile(“file://Silvia/tuuli_client/processing_13/sound_01.wav”);
}
player.rewind();
player.play();
break;
case ‘s’: // STOP PLAY
if ( player != null) {
if ( player.isPlaying() ) {
player.pause();
}
}
break;
}
}

Our boxes are able to comunicate between them. For this reason we implement the Processing code with two variants: one gave a server role to the PC connected to box A and the other a client role to the PC connected to box B. Now the boxes can send and recive data (sounds) via wireless, using a shared folder.
Box A
In the begining of the code we put the role “server“.

Server server;
boolean serverRunning;
char message;

In the ” void draw” we put a piece of code that checks if there are data (sounds) from the PC of the other box.

void draw()
{
if(serverRunning == true) {
//check for the next client in line with a new message
Client thisClient = server.available();
//is there a client?
if(thisClient != null) {
//check to see if there is a message from the client
if(thisClient.available() > 0) {
// read in the message
String m = thisClient.readString();
message = m.charAt(0);
//data = 112;
// println(data);
messageWaiting = true;
dropCounter = 0;//set the counter for the number of times the string drops to 0
dropString() ;
}
}
}

Box B
In the begining of the code we put the role “client“.

Client client;
boolean serverRunning;
char message;

In the “void setup” we put the IP number of the Pc connected to box A.

//server = new Server(this, 10002); // server
//serverRunning = true; //server
client = new Client(this, “172.16.6.52″, 10002);
data = 0;//empty data at start
}

f

ARDUINO CODE

We declared the variables.

int motorPinA = 8;                 // motorPin1 connected to digital pin 8 (with a supply of energy of 5V)
int motorPinB = 2;                 // motorPin1 connected to digital pin 2
int pullDownPin = 4;               // control the switch for the pull down
int sphereUpPin = 5;               // control the switch closed and open by the sphere
int lidClosePin = 3;               // control the switch for the lid
boolean lidCloseVal = true;
boolean pullUpVal = true;
boolean isRecording = false;
boolean wasRecording = false;
boolean isPlaying = false;

In the “setup” of Processing we declared the port in order to excange data with Arduino.

String portName = Serial.list()[1];
port = new Serial(this, portName, 9600);

In the “void loop” we take the switch values and relate each one to a letter that send a precise command to Processing. For example if the lid switch is open, Arduino sends to Processing the letter “r” and the value. Processing recives the command and starts to record.

if (recordingFlag == false){
if (lidClose==0){//start recording
Serial.print(‘r’);
recordingFlag = true;
delay(10);
}
}
else{// recording flag is true
if (lidClose==1){//stop recording
Serial.print(‘f’);
recordingFlag = false;
delay(10);
}
}

f

DOWNLOADS

Tuuli Processing code [ZIP of sketch folder – 1,4 Mb] [.txt – 5 Kb]
Tuuli Arduino code (box with the red cord) [ZIP of sketch folder - 66,4 Kb] [.txt – 4 Kb]
Tuuli Arduino code (matrioska box) [ZIP of sketch folder- 44,2 Kb] [.txt – 3 Kb]

To run these files you need Arduino and Processing installed on your computer. Unzip them and copy the entire sketch folder into the Processing or Arduino folders in your Documents folder. Then open them from within Arduino or Processing as appropriate.

f

intro | users and context | the Tuuli family | istruction manual | what’s in common: audio |
what’s different: behaviour | technology | project history | prototyping | code |
other opportunities | credits | downloads