Wednesday, 4 June 2014

processing

code 1 (oocsi)

import nl.tue.id.oocsi.*;
import oscP5.*;
import netP5.*;

NetAddress myRemoteLocation4;
int fillColor = 255;
int position = 0;
int volume;

OscP5 oscP5;


void setup() {
 size(800, 800);
 noStroke();

 // connect to OOCSI server running on the same machine (localhost)
 // with "receiverName" to be my channel others can send data to
 OOCSI oocsi = new OOCSI(this, "thanok", "diserver.id.tue.nl");

 // subscribe to channel "testchannel"
 oocsi.subscribe("awesome");

 oscP5 = new OscP5(this, 5005);
 myRemoteLocation4 = new NetAddress("127.0.0.1", 5006);
}

void draw() {
 background(255);
 fill(fillColor, 120, 120);
 rect(100, position, 200, 200);

 OscMessage myMessage4 = new OscMessage("");
 myMessage4.add(volume);
 oscP5.send(myMessage4, myRemoteLocation4);
}

void handleOOCSIEvent(OOCSIEvent event) {
 // assign the new fill color from the OOCSI event
 volume = event.getInt("volume", 0);
 effect = event.getInt("effect", 0);
 pitch = event.getInt("pitch", 0);
 // assign the new y position from the OOCSI event

}

code 2 

import oscP5.*;
import netP5.*;
import processing.serial.*;
import nl.tue.id.oocsi.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
NetAddress myRemoteLocation2;
NetAddress myRemoteLocation3;
NetAddress myRemoteLocation4;
OOCSI oocsi;

Serial myPort; // we're calling the port "myPort"
String dataReading = "";
int x; // this is val1 on the Arduino
int y;
int z;
int lastz;

void setup() {
 size(500,500); // size of the window
 myPort = new Serial(this, Serial.list()[0], 115200); // reading it right
 myPort.bufferUntil('\n'); // goes on until manual stop
 oocsi = new OOCSI(this, "thanoss", "diserver.id.tue.nl");

 oscP5 = new OscP5(this,5001);
 myRemoteLocation = new NetAddress("127.0.0.1", 5004);
 myRemoteLocation2 = new NetAddress("127.0.0.1", 5002);
 myRemoteLocation3 = new NetAddress("127.0.0.1", 5003);
}

void draw() {
 background(255);
 noStroke();
 fill(255,0,0,90);
 rect(30,0,30,x/4);
 fill(0);
 textAlign(CENTER, BOTTOM);
 text("softpot1",45,400);
 text(x, 45, 420);
 noStroke();
 fill(0,255,0,90);
 rect(100,0,30,y/4);
 fill(0);
 textAlign(CENTER, BOTTOM);
 text("softpot2",115,400);
 text(y,115,420);
 noStroke();
 fill(0,0,255,90);
 rect(180,0,30,z/4);
 fill(0);
 textAlign(CENTER, BOTTOM);
 text("softpot3",195,400);
 text(z,195,420);

 OscMessage myMessage = new OscMessage("");
 myMessage.add(x);
 oscP5.send(myMessage, myRemoteLocation);

 OscMessage myMessage2 = new OscMessage("");
 myMessage2.add(y);
 oscP5.send(myMessage2, myRemoteLocation2);

 OscMessage myMessage3 = new OscMessage("");
 myMessage3.add(z);
 oscP5.send(myMessage3, myRemoteLocation3);



    oocsi
 .channel("awesome")
 .data("softpot", x)
 .data("softpot2", y)
 .data("softpot3", z)
 .send();

}

void serialEvent(Serial myPort) {
 try {
   dataReading = myPort.readString();
   if(dataReading!=null) {
     String[] trim = split(dataReading,'>');
     String[] pieces = split(trim[0], ';');

     x = parseInt(pieces[0]);
     y = parseInt(pieces[1]);
     z = parseInt(pieces[2]);

   }
 }
 catch (Exception e){
   println("Error");
 }
}





Tuesday, 3 June 2014

Final exhibition codes

ARDUINO:
int softpotPin0 = A0; //analog pin 0
int softpotPin1 = A1; //analog pin 1
int softpotPin2 = A2; //analog pin 2
void setup() {

Serial.begin(115200);
digitalWrite(softpotPin0, HIGH); //enable pullup resistor
digitalWrite(softpotPin1, HIGH); //enable pullup resistor
digitalWrite(softpotPin2, HIGH); //enable pullup resistor
}
void loop(){

 int softpotReading0 = analogRead(softpotPin0);
 int softpotReading1 = analogRead(softpotPin1);
 int softpotReading2 = analogRead(softpotPin2);

 int val1 = map(softpotReading0, 0, 1023, 127, 0);
 int val2 = map(softpotReading1, 0, 1023, 127, 0);
 int val3 = map(softpotReading2, 0, 1023, 127, 0);

 Serial.print(val1);
Serial.print(";");
Serial.print(val2);
Serial.print(";");
Serial.print(val3);
Serial.println(">");
}

PROCESSING (+max):
import oscP5.*;
import netP5.*;
import processing.serial.*;
import nl.tue.id.oocsi.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
NetAddress myRemoteLocation2;
NetAddress myRemoteLocation3;
NetAddress myRemoteLocation4;
OOCSI oocsi;

Serial myPort; // we're calling the port "myPort"
String dataReading = "";
int x; // this is val1 on the Arduino
int y;
int z;
int lastz;

void setup() {
 size(500,500); // size of the window
 myPort = new Serial(this, Serial.list()[0], 115200); // reading it right
 myPort.bufferUntil('\n'); // goes on until manual stop
 oocsi = new OOCSI(this, "thanos", "diserver.id.tue.nl");

 oscP5 = new OscP5(this,5001);
 myRemoteLocation = new NetAddress("127.0.0.1", 5004);
 myRemoteLocation2 = new NetAddress("127.0.0.1", 5002);
 myRemoteLocation3 = new NetAddress("127.0.0.1", 5003);
}

void draw() {
 background(255);
 noStroke();
 fill(255,0,0,90);
 rect(30,0,30,x/4);
 fill(0);
 textAlign(CENTER, BOTTOM);
 text("softpot1",45,400);
 text(x, 45, 420);
 noStroke();
 fill(0,255,0,90);
 rect(100,0,30,y/4);
 fill(0);
 textAlign(CENTER, BOTTOM);
 text("softpot2",115,400);
 text(y,115,420);
 noStroke();
 fill(0,0,255,90);
 rect(180,0,30,z/4);
 fill(0);
 textAlign(CENTER, BOTTOM);
 text("softpot3",195,400);
 text(z,195,420);

 OscMessage myMessage = new OscMessage("");
 myMessage.add(x);
 oscP5.send(myMessage, myRemoteLocation);

 OscMessage myMessage2 = new OscMessage("");
 myMessage2.add(y);
 oscP5.send(myMessage2, myRemoteLocation2);

 OscMessage myMessage3 = new OscMessage("");
 myMessage3.add(z);
 oscP5.send(myMessage3, myRemoteLocation3);



    oocsi
 .channel("thanothijs")
 .data("softpot", x)
 .data("softpot2", y)
 .send();

}

void serialEvent(Serial myPort) {
 try {
   dataReading = myPort.readString();
   if(dataReading!=null) {
     String[] trim = split(dataReading,'>');
     String[] pieces = split(trim[0], ';');

     x = parseInt(pieces[0]);
     y = parseInt(pieces[1]);
     z = parseInt(pieces[2]);

   }
 }
 catch (Exception e){
   println("Error");
 }
}

Monday, 2 June 2014

import cc.arduino.*;
import processing.serial.*;
import nl.tue.id.oocsi.*;
import themidibus.*;

Arduino arduino;
OOCSI oocsi;
MidiBus busA;


int potPin=0;
int potPin1=1;
int potPin2=2;
int val;
int val1;
int val2;

void setup() {

  arduino = new Arduino(this, Arduino.list() [0], 57600);
  arduino.pinMode(potPin, Arduino.OUTPUT);
  arduino.pinMode(potPin1, Arduino.OUTPUT);
  arduino.pinMode(potPin2, Arduino.OUTPUT);


  MidiBus.list();
          
  busA = new MidiBus(this, "IAC Bus 1", "IAC Bus 1");


}

void draw() {
val = arduino.analogRead(potPin)/8;
val1 = arduino.analogRead(potPin1)/8;
val2 = arduino.analogRead(potPin2)/8;


busA.sendControllerChange(0, 0, val);
busA.sendControllerChange(0, 1, val1);
busA.sendControllerChange(0, 2, val2);

println(val + " - " + val1 + " - " + val2);
}

Monday, 26 May 2014

3 softpots connected to Ableton + MIDIBUS

import cc.arduino.*;
import processing.serial.*;
import nl.tue.id.oocsi.*;
import themidibus.*;

Arduino arduino;
OOCSI oocsi;
MidiBus busA;


int potPin=0;
int potPin1=1;
int potPin2=2;
int val;
int val1;
int val2;

void setup() {
 
  arduino = new Arduino(this, Arduino.list() [0], 57600);
  arduino.pinMode(potPin, Arduino.OUTPUT);
  arduino.pinMode(potPin1, Arduino.OUTPUT);
  arduino.pinMode(potPin2, Arduino.OUTPUT);
 
 
  MidiBus.list();
           
  busA = new MidiBus(this, "Output to Audio software", "Output to Audio software"); // Change these names to the name of the port, of your 1st sensor

 
}

void draw() {
val = arduino.analogRead(potPin)/8;
val1 = arduino.analogRead(potPin1)/8;
val2 = arduino.analogRead(potPin2)/8;


busA.sendControllerChange(0, 0, val); //Send a controllerChange to OutgoingA and OutgoingC through busA
busA.sendControllerChange(0, 1, val1); //Send a controllerChange to OutgoingB through busB
busA.sendControllerChange(0, 2, val2);


}

Sunday, 25 May 2014

3 softpots connected to processing

After uploading StandarFirmata to arduino, File -> Examples -> Firmata -> StandarFirmata

run this code on processing:




import cc.arduino.*;
import processing.serial.*;

Arduino arduino;

int potPin=0;
int potPin1=1;
int potPin2=2;
int val;
int val1;
int val2;
void setup() {
 
  arduino = new Arduino(this, Arduino.list() [0], 57600);
  arduino.pinMode(potPin, Arduino.OUTPUT);
  arduino.pinMode(potPin1, Arduino.OUTPUT);
  arduino.pinMode(potPin2, Arduino.OUTPUT);
}

void draw() {
val = arduino.analogRead(potPin)/8;
val1 = arduino.analogRead(potPin1)/8;
val2 = arduino.analogRead(potPin2)/8;

print("softpot0:  ");
print(val);
print("   softpot1:  ");
print(val1);
print("      softpot2:  ");
print(val2);
println();


}

Thursday, 22 May 2014

midi oocsi

import processing.serial.*;
import nl.tue.id.oocsi.*;

OOCSI oocsi;

Serial myPort; // we're calling the port "myPort"
String dataReading = "";
int x; // this is val1 on the Arduino
int y;
int z;

void setup() {
  size(500,500); // size of the window
  myPort = new Serial(this, Serial.list()[0], 115200); // reading it right
  myPort.bufferUntil('\n'); // goes on until manual stop
  oocsi = new OOCSI(this, "thanos", "diserver.id.tue.nl");
}

void draw() {
  background(255);
  noStroke();
  fill(255,0,0,90);
  rect(30,0,30,x);
  fill(0);
  textAlign(CENTER, BOTTOM);
  text("softpot",45,160);
  text(x, 45, 180);
  noStroke();
  fill(0,255,0,90);
  rect(100,0,30,y);
  fill(0);
  textAlign(CENTER, BOTTOM);
  text("softpot2",115,160);
  text(y,115,180);
  noStroke();
  fill(0,0,255,90);
  rect(180,0,30,z);
  fill(0);
  textAlign(CENTER, BOTTOM);
  text("softpot3",195,160);
  text(z,195,180);
 
   
      oocsi
  .channel("thanothijs")
  .data("softpot", x)
  .data("softpot2", y)
  .send();

}

void serialEvent(Serial myPort) {
  try {
    dataReading = myPort.readString();
    if(dataReading!=null) {
      String[] trim = split(dataReading,'>');
      String[] pieces = split(trim[0], ';');
    
      x = parseInt(pieces[0]);
      y = parseInt(pieces[1]);
      z = parseInt(pieces[2]);
    
    }
  }
  catch (Exception e){
    println("Error");
  }
   
 
}

Thursday, 15 May 2014

Arduino + 3 softpots code to Processing ::

Arduino code:
 
#include <MIDI.h>
int softpotPin0 = A0; //analog pin 0
int softpotPin1 = A1; //analog pin 1
int softpotPin2 = A2; //analog pin 2
void setup() {
//MIDI.begin();
Serial.begin(115200);
digitalWrite(softpotPin0, HIGH); //enable pullup resistor
digitalWrite(softpotPin1, HIGH); //enable pullup resistor
digitalWrite(softpotPin2, HIGH); //enable pullup resistor
}
void loop(){

 int softpotReading0 = analogRead(softpotPin0);
 int softpotReading1 = analogRead(softpotPin1);
 int softpotReading2 = analogRead(softpotPin2);

 int val1 = map(softpotReading0, 0, 1023, 0, 127);
 int val2 = map(softpotReading1, 0, 1023, 0, 127);
 int val3 = map(softpotReading2, 0, 1023, 0, 127);

 Serial.print(val1);
Serial.print(";");
Serial.print(val2);
Serial.print(";");
Serial.print(val3);
Serial.println(">");




















Processing code:

import processing.serial.*;

Serial myPort; // we're calling the port "myPort"
String dataReading = "";
int x; // this is val1 on the Arduino
int y;
int z;

void setup() {
  size(500,500); // size of the window
  myPort = new Serial(this, Serial.list()[0], 115200); // reading it right
  myPort.bufferUntil('\n'); // goes on until manual stop
}

void draw() {
  background(255);
  noStroke();
  fill(255,0,0,90);
  rect(30,0,30,x);
  fill(0);
  textAlign(CENTER, BOTTOM);
  text("softpot",45,160);
  text(x, 45, 180);
  noStroke();
  fill(0,255,0,90);
  rect(100,0,30,y);
  fill(0);
  textAlign(CENTER, BOTTOM);
  text("softpot2",115,160);
  text(y,115,180);
  noStroke();
  fill(0,0,255,90);
  rect(180,0,30,z);
  fill(0);
  textAlign(CENTER, BOTTOM);
  text("softpot3",195,160);
  text(z,195,180);
 
}

void serialEvent(Serial myPort) {
  try {
    dataReading = myPort.readString();
    if(dataReading!=null) {
      String[] trim = split(dataReading,'>');
      String[] pieces = split(trim[0], ';');
     
      x = parseInt(pieces[0]);
      y = parseInt(pieces[1]);
      z = parseInt(pieces[2]);
     
      print(x);
      print("\t");
      print(y);
      print("\t");
      println(z);
    }
  }
  catch (Exception e){
    println("Error");
  }
}


 




Visualization of 3 softpots on Processing