Skip navigation

5. Code

We made Processing and Arduino communicate with each other to translate the physical inputs of the sensors into useful data for Processing, manage these data and change the physical behaviour of the installation.


From Arduino to Processing

We used an Arduino board in which we connected each sensor and with a piece of Arduino code detected whenever a switch sensor was pressed.

The checkButtons function continually reads the signals for each switch sensor. When a person walk over one, Arduino receives signal from that switch, and sends this information to Processing.

With the serial library we can send signals from Arduino to Processing.

The same thing happens to all the switches. In this way the Processing application we developed knows the path of the users inside the alley.
For instance, if Arduino sends to Processing a value “1″ and then a value “2″ (watch the image above) it means that a person walks over the A switch sensor first, then over the B sensor. It means that a person is entering the alley, and Processing understand it perfectly. The inverse combination, B first then A, means that someone is exiting the alley.

Manage data by Processing

Every time a switch sensor is pressed, Arduino sends a signal to Processing, which stores in an array called path the order of switches pressed to understand the direction of movement.

Processing continually checks the status of the path array and reads two positions at the time in order to detect an A-B or B-A passage. The number of people in the alley increases, and if equal to one the installation is ready to start.

We saw how to let Processing understand movement in the alley. Depending on what happens there, the installation has different behaviors.

We wrote the logic statement of the Processing application thinking what must happen when the user does something. The actuator function works as the mind of the application. It takes all the information and decides the behaviour of the phone and TV.

The sound come always from the telephone. In relationship to the status of the installation, it could play the audioguide or ring.
We have described how we physically put earphones inside the phone.
The sound is played by the Processing application that knows when a user picks up the phone, and plays the right audio.
The piece of code that plays the sound (using the Minim library) is part of the logic function called
actuator.

The TV works in the same way as the phone. The logic of the Processing application knows when the screen has to be black, and when the video has to start. This coincides with the moment when the user, alone during the night, picks up the phone after it rings.

Memento | Context | Experience | Process | Prototype | Code | Final considerations | Credits | Downloads