New Video Documentation for Radius Music/Processing Code

22Jun10
//Processing Code (needs an Arduino)

import processing.serial.*;
import oscP5.*;
import netP5.*;
import fullscreen.*;
FullScreen fs;

OscP5 oscP5;
NetAddress myRemoteLocation;
PFont deja;
Serial port;

int time = 0;
int roundingTime = 3200; //sensor rot time in millis
int clearTime = 0;
int refresh = 7000; //number of pixels before recalling background(0)
float r, inR; //radius variables

//set visual radius limits
int minVal = 50;
int maxVal = 400;
//set frequency limits
int minFreq = 100;
int maxFreq = 1000;

void setup(){
  size(screen.width, screen.height, P2D);
  background(0);
  //open the Serial Port
  println(Serial.list());
  port = new Serial(this, Serial.list()[0], 9600);
  port.bufferUntil('\n');
  //initialise fullscreen
  fs = new FullScreen(this);
  fs.enter();
  //open OSC link with puredata
  oscP5 = new OscP5(this, 12000);
  myRemoteLocation = new NetAddress("127.0.0.1", 12000);
}

void draw(){
  
  int currentTime = millis();
  float m = (currentTime%roundingTime)* TWO_PI / roundingTime;
  
  //set the x,y coords for the visual
  float rx = (sin(m)*r+width/2);
  float ry = (cos(m)*r+height/2);
  stroke(255);
  strokeWeight(1);
  point(rx, ry);
  
  //send data to puredata
  float freq = map(r, minVal, maxVal, minFreq, maxFreq);
  sendDist(freq);

  refresh();
}

void mousePressed(){
  background(0);
}

void refresh(){
  clearTime +=1;
  if (clearTime>refresh){
    background(0);
    clearTime = 0;
  }
}

void serialEvent(Serial port){
  String input=port.readStringUntil('\n');

  if (input != null){
    input=trim(input);
    inR = float(input);
    r = map(inR, 0, 1023, minVal, maxVal);
    r = constrain(inR, minVal, maxVal);
  }
}

void sendDist(float distance){
  OscMessage myMessage = new OscMessage("/sensor1");  
  myMessage.add(distance);
  oscP5.send(myMessage, myRemoteLocation);
}
Advertisements


No Responses Yet to “New Video Documentation for Radius Music/Processing Code”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: