About the assignment: INTERFACE AND APPLICATIONS PROGRAMMING

Write an application that interfaces with an input &/or output device

language

I am really interested in how Processing can be used to connect visual arts and visual literacy with technology.

I downloaded here the software and I started with the tutorials available on the website.

tests

After a day spent watching and trying various tutorials I started working with simple codes.

The first one is a sort of compendium of basic function using background, shapes, color, mouse position.

One test I did was with the microphone:

/**
* This sketch demonstrates how to read microphone signal and draw a waveform
* by Davide Prete
*/

import ddf.minim.*;

Minim minim;
AudioInput in;
AudioRecorder recorder;

void setup()
{
size(1000, 1000, P3D);

minim = new Minim(this);

in = minim.getLineIn();

}

void draw()
{
background(255);
stroke(0);
// draw the waveforms
// the values returned by left.get() and right.get() will be between -1 and 1,
// so we need to scale them up to see the waveform
for(int i = 0; i < in.bufferSize() - 1; i++)
{
line(i, 500 + in.left.get(i)*500, i+1, 500 + in.left.get(i+1)*500);

}
}

application that interfaces with light sensor

Using the example wrote by by Anna K.F and Shawn Wallace I tried to learn how to show data recorded by sensors. I used different boards with different sensors I created before (light sensor board and motion sensor) and see if I can run a sketch with it.

After connecting my input device via FTDI cable and run the sketch I can visualize the changing of the design on the screen. I had to set up the second serial port becouse my Windows machine was reading my board as COM6 (second in the list, so (1)).

/**
* Serial Input to Randomly Colored Lines
*
* Read data from the serial port and changes the color of a lines drawing
* across the screen the height of the lines changes relative to the values
* recieved from the sensor.
*
* written by Shawn Wallace
* modified by Davide Prete
*/

import processing.serial.*;

Serial serialPort; // Create object from Serial class
int col = 0; //starting point for the lines on the screen

void setup() {
size(1024, 1024); //set window size
background(0); //set background color to black
stroke(255); // set stroke to white
smooth(); //smooth out the lines

// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On my Windows machines, this opens COM6.
// It is the second port so (1).
println(Serial.list());
serialPort = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
//if there is data comming in from the serial port
while (serialPort.available () > 0) {
//set the variable height equal to the data comming in.
int height = serialPort.read();
//to draw rows across the screen in columns
//then wrap back to other side of the screen
col = col+1;
if (col > 1024) {
col = 0;
}
println(height); //print the values read from the serial port to the console
//if the serial values are greater than 10
if (height > 10) {
//draw a line that increases / decreases based on sensor output.
//adjusted for sensor values.
line(col, (height-125)+512, col, 512-height);
}
//EXPERIMENT WITH THE VISUALIZATION BELOW
//currently draws random strokes for the full range of color
stroke((int)random(255), (int)random(255), (int)random(255));
}
}

© 2014, Davide Prete, Washington DC