For this week assignment: write an application that interfaces with an input&/or outputdevice I start by taking a look at the different programming methods and tools that are available. I download and play around with Python, Arduino, Processing, Scratch. I also keep trying to understand C in a deeper way. Links to the different platforms can be found in the class home.

I want to make an interface for the light sensor board. My first idea is to start by animating the eyes of a face in scratch to open or close them depending on the amount of light. But then I try processing and I start to think of different possible interfaces. By looking at last year’s work I find Matt Keeter multi touch synth wich I find beautiful, so I decide to try and transform the light data into sound.

For that I visit The Beads Project site and download their library. I make all of the tutorial examples and I use Lesson 10 Interaction program as the base for mine. This program changes the output sound depending on the position (x,y) of the mouse. For my program I will need to change the input from the mouse to the serial port and obtain the value of the light sensor. To do that I use the serialRead example in Processing library, but I wouldn’t have been able put the pieces together to work without the help of Cagri... Thanks!

Here is a video of the wave. I think I need to adjust the multipliers of the values in order to perceive the differences of sound in a more clear way.

You can download the code here. Or just copy and paste:

import beads.*;

AudioContext ac;
Glide carrierFreq, modFreqRatio;
Serial myPort; // Create object from Serial class
int val2=0;
int val3=0;
int val4=0;
int low=0;
int high=0;
int value=0;

void setup() {
String portName = Serial.list()[4];
myPort = new Serial(this, portName, 9600);
ac = new AudioContext();

//we use the Glide object because it smooths the input.
carrierFreq = new Glide(ac, 1000);
modFreqRatio = new Glide(ac, 1);

if ( myPort.available()>0) { // If data is available,

val = val2;
val2 = val3;
val3 = val4;
val4 =; // read it and store it in val

Function modFreq = new Function(carrierFreq, modFreqRatio) {
public float calculate() {
return x[0] * x[1];


if(val==1 && val2==2 && val3==3 && val4==4){
background(255); // Set background to white;;
value=256*high + low;
WavePlayerfreqModulator = new WavePlayer(ac, modFreq, Buffer.SINE);
Function carrierMod = new Function(freqModulator, carrierFreq) {
public float calculate() {
return x[0] * 400.0 + x[1];
WavePlayerwp = new WavePlayer(ac, carrierMod, Buffer.SINE);
Gain g = new Gain(ac, 1, 0.1);

* Drawing colors.
color fore = color(0,0,0);
color back = color(255,255,255);

* Just do the work straight into Processing's draw() method.
void draw() {
//set the background
Arrays.fill(pixels, back);
//scan across the pixels
for(inti = 0; i< width; i++) {
//for each pixel work out where in the current audio buffer we are
intbuffIndex = i * ac.getBufferSize() / width;
//then work out the pixel height of the audio data at that point
intvOffset = (int)((1 + ac.out.getValue(0, buffIndex)) * height / 2);
//draw into Processing's convenient 1-D array of pixels
pixels[vOffset * height + i] = fore;
//mouse listening code here



Ignacio Peydro, November 2012.