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");
 }
}





No comments:

Post a Comment