Skip navigation

… code

“Don’t worry about a thing
‘Cause every little thing
Gonna be alright”

Due to our project’s structural complexity, we wrote the code for an Arduino board, controlling the presence sensors, and for two computers running Processing, collecting the informations from detectors and camera and giving the output for two projectors and two couples of speakers.

Syncronizing these three software controllers and communicate to each other represents a large amount of hard-coding, but, as said before, dividing a big problem in little small steps (or applications) could give a great help.

dscn5842.jpg

Here we’ll give an overview on our code with some relevant extractions to better explain it.

 

Arduino code

The Arduino board is directly connected to the client computer, that manages the global communication for the installation, through USB wiring. It make possible a serial communication in wich each information is vehiculed one bit at one time.

Declared the switch value, commonly “HIGH” or “LOW”, Arduino reads it from the sensor’s gateway board (plugged on its “switch” pin) and when it is “HIGH” sends it out to the serial port.

switchValue = digitalRead(switchPin);

if (switchValue == HIGH) {

Serial.println(switchValue);

We also apply a digital-write command to another pin in order to let its plugged led blink. It makes easy to understand when the sensor is “HIGH”.

digitalWrite(ledPin, HIGH);

delay(20);

 

Processing code

To be able to share times and data for two projectors, their own computers are network-connected each other. Using the Processing Core Network Library we could define the client computer, a gateway that collects informations and sends data and commands, and the server computer, a simple receiver.

import processing.net.*;

Client client;

In order to read the signal from the Arduino board and start the interaction, we import the Processing Core Serial Library. We also need the Processing Core Video Library, the ESS Audio Library by Krister Olsson and the Fullscreen Library by superduper.org, to be able to capture and play movies, play audio samples and render output images in full screen mode. After the setup phase we can start capturing from the camera.

void captureEvent(Capture myCapture) {

myCapture.read();

}

The images are just buffered, not yet stored. In the draw phase we could define case by case the installation behaviors such as recording the video frames on the server computer, send it the start signal and jump to the next case.

case 2: // setup counter and tell the server to start

time = millis() + 23000;

client = new Client(this, “172.16.0.155″, 10002);

client.write(buffer);

mm = new MovieMaker(this, 320, 221, “/Volumes/serverComputer/processing/serverside/data/drawing”+movies+”.mov”, 9);

println(”mode ” + mode + ” ok!”);

mode = 3;

break;

It’s always a good idea to end a case with a debug message so, if an error occurs, it’s possible to know exactly where to find it.

< previous | next >

PASSAGE OF TIME
about | experience | technology | prototype | code | issues | reflections | who did what
download