write an application that interfaces with an input &/or output device that you made
I used a Processing GUI library called "controlP5" .
The way to import libraries is clicking Sketch > Import Library... > Add Library...
Processing code is here:
// FabAcademy2016 week16 interface programming
// 2016.5.24
import processing.serial.*;
import controlP5.*;//controlP5 is a GUI library >> http://www.sojamo.de/libraries/controlP5/
Serial myport;
ControlP5 cp5;
int col =0;
float n;
void setup(){
size(500, 300);
background(20,20,20);
smooth();
cp5 = new ControlP5(this);
//make serial1 button GUI
cp5.addButton("serial1")
.setValue(0)
.setPosition(50,100)
.setSize(100,19)
;
//make serial0 button GUI
cp5.addButton("serial0")
.setValue(0)
.setPosition(50,200)
.setSize(100,19)
;
//show ports on console
println(Serial.list());
println(Serial.list()[0]);
println(Serial.list()[1]);
println(Serial.list()[2]);
println(Serial.list()[3]);
//open port
myport = new Serial(this, Serial.list()[3],9600);
println(myport.available());
myport.write('0');
frameRate(2);
textSize(20);
}
void draw(){
//println(serialPort.available()); // check if the data is coming or not
float amp = myport.read();
println("myport.read() is " + amp);
background(10,10,10);
}
void keyPressed(){
if(key== '1'){
myport.write("1");
text("serial 1 is sent",200,100+15);
}else if(key == '0'){
myport.write("0");
text("serial 0 is sent",200,200+15);
}
}
public void controlEvent(ControlEvent theEvent) {
println(theEvent.getController().getName());
n = 0;
}
// function colorA will receive changes from
// controller with name serial1
public void serial1(int theValue) {
println("a button event from serial1: "+theValue);
myport.write("1");
text("serial 1 is sent",200,100+15);
}
// function colorA will receive changes from
// controller with name serial1
public void serial0(int theValue) {
println("a button event from serial0: "+theValue);
myport.write("0");
text("serial 0 is sent",200,200+15);
}
Download the Processing code for output device