The processing code



-------------------------------processing code:

import traer.physics.*;

import krister.Ess.*;

import processing.video.*;

import processing.serial.*;

ParticleSystem physics;

Capture myCapture;

Serial myPort;

Movie myMovie, myMovie2, kamel1, kamel2, free1, free2, currentMovie;

//serial

int gloveswitch1;

int gloveswitch2;

int gloveswitch3;

int gloveswitch4;

int gloveswitch5;

int gloveswitch6;

int gloveswitch7;

int gloveswitch8;

int slide; //ADC0

int slide1; //ADC1

int pslide;

int rslide;

String accumulation = "";

//PImage blank;

String myblank = "file:///c:/Documents and Settings/itp student/My Documents/Processing/VJ9nine/data/blank.jpg";

//PImage blank;

PImage blank = loadImage(myblank);

//myblank = blank;

PImage currentClip;

PImage secondClip;

PImage Temp;

boolean switch2 = false;

boolean fadeSwitch = false;

boolean wipeLSwitch = false;

boolean effectSwitch = false;

//variables for ess

Channel mySound;

int writeSamplesSize;

int writeUpdateTime;

int lastCue;

// buffer

float znew = 0;

byte[] drawBuffer;

int drawBufferLoad;

int drawBufferStartTime;

//Variables for buffer, sliding effect

boolean once = false;

int[] buffer;

float bufferOffset, newBufferOffset;

// Variables for bgnd subtraction

boolean switch1 = false;

int video_width = 320;

int video_height = 240;

//int frameRate = 15;

int num_pixels = (video_width * video_height);

PImage background_img;

//Variable for explode

PImage[] savedFrame = new PImage[2];

PImage img; // The source image

int cellsize =4; // Dimensions of each cell in the grid

int COLS, ROWS; // Number of columns and rows in our system

int thisispressed;

//Variables for 3D Rotate

float al = 0.0;

float rSize;

//Variables for Particle Drawing

ArrayList a;

float z;

//Variables for brightness tracking

int xFound = 0; // initialize the location of the brightnessTracker

int yFound = 0;

float targetHue = 0.0; //set some numbers for the target you are chasing

float targetSaturation = 0.0;

float targetBrightness = 255.0;

//Variables for Physics effect

Particle[] pin;

Particle[] anchor;

Spring[] spr;

//Variables for Pictue Loader

String myPics = "file:///c:/Documents and Settings/itp student/My Documents/Processing/VJ9nine/code/";

String theList[] = loadStrings(myPics);

PImage[] thePImageList = new PImage[500];

float z2;

//Variables for BBoy Clips

float xmov = 0;

float diss = 255;

int counter = 0;

//TNO Pictures

PImage ap,bp,cp,dp,ep,fp,gp,hp,ip; // Declare variable "a" of type PImage

PImage jp, kp,lp,mp,np,op,pp,qp;

PImage djdano;


//boolean switch3 = false;

////////////////////////////////////SETUP/////////////////////////////////////////

void setup() {

size(320, 240, P3D);

ellipseMode(CENTER);

rectMode(CENTER);

framerate(24);

// TNO Pictures Setup

ap= loadImage ("45957275_4c491153da_t.jpg");

bp =loadImage ("51338624_1ae822a0e9_t.jpg");

cp=loadImage ("53131432_5eeef34ccb_t.jpg");

dp=loadImage ("59018093_10c4bc633a_t.jpg");

fp=loadImage ("59986914_693f630353_t.jpg");

gp=loadImage ("62597711_016ab94e70_t.jpg");

hp=loadImage ("63126287_8e157e7fd8_t.jpg");

ip=loadImage ("53131590_1090970cb5_t.jpg");

jp=loadImage ("63127685_8f07cd6295_t.jpg");

kp=loadImage ("51339263_c3c5ef51ed_t.jpg");

lp=loadImage ("59018306_78826a4a45_t.jpg");

mp=loadImage ("69966089_b6e32a6ba6_t-1.jpg");

np=loadImage ("59018856_81ba052a89_t.jpg");

op=loadImage ("64588443_7afb109230_t.jpg");

pp=loadImage ("69517634_eedc3a2bcb_t.jpg");

qp=loadImage ("69517904_95a8398917_t.jpg");

djdano= loadImage ("DJ.jpg");

//Picture Loader Setup

for (int i = 0; ithePImageList[i] = loadImage(theList[i]);

}

//Physics Drawing Setup

physics = new ParticleSystem( 0.0, 0.05 );

pin = new Particle[20];

anchor = new Particle[20];

spr = new Spring[20];

for ( int i = 1; i < pin.length; i++ ) {

pin[i] = physics.makeParticle( 2.0, random(50,150), random(50,150), 0 );

anchor[i-1] = physics.makeParticle( 1.0, random(50,150), random(50,150), 0 );

spr[i] = physics.makeSpring( pin[i], anchor[i-1], 1.0, 0.1, 300 );

}

//Buffer setup

background_img = new PImage(video_width, video_height);

buffer = new int[width*height];

bufferOffset = newBufferOffset = 0.0;

// Video capture and clips setup

currentMovie = new Movie(this, "blank.jpg");

myCapture = new Capture(this, width, height, 30);

myMovie = new Movie(this, "SmokeyTexture.mov");

myMovie2 = new Movie(this, "Tunnel2.mov");

kamel1 = new Movie(this, "Kamel1.mov");

kamel2 = new Movie(this, "Kamel2.mov");

free1 = new Movie(this, "Free1.mov");

free2 = new Movie(this, "Free3.mov");

currentClip = myCapture;

secondClip = blank;

//myMovie.framerate(15);

//myMovie2.framerate(15);

myMovie.loop();

myMovie2.loop();

kamel1.loop();

kamel2.loop();

free1.loop();

free2.loop();

framerate(30);

// Explode setup

thisispressed=0;

savedFrame[0] = new PImage(video_width,video_height);

savedFrame[1] = new PImage(video_width,video_height);

img = savedFrame[1]; // Load the image

COLS = width/cellsize; // Calculate # of columns

ROWS = height/cellsize; // Calculate # of rows

colorMode(RGB,255,255,255,100); // Setting the colormode

// 3D Rotate Setup

rSize = width/4;

// Particle Drawing Setup

a = new ArrayList();

//ESS setup

Ess.start(this);

mySound=new Channel("Beat02.aif");

mySound.normalize();

mySound.setupFFT(512);

mySound.updateWriteSamples=true;

writeSamplesSize=mySound.writeSamples.length;

drawBuffer=new byte[writeSamplesSize*2];

// based on our sampleRate and writeSamplesSize, figure out how often writeSamples is updated

writeUpdateTime=mySound.ms(writeSamplesSize);



/////// SERIAL/////////////

// List all the available serial ports:

println(Serial.list());

// I know that the first port in the serial list on my mac

// is always my Keyspan adaptor, so I open Serial.list()[0].

// Open whatever port is the one you're using.

myPort = new Serial(this, Serial.list()[0], 9600);

println(Serial.list());

//prime the pump in case your microcontroller is stuck in serin

myPort.write(65);

}


void captureEvent(Capture myCapture) {

myCapture.read();

}

/*

void movieEvent(Movie m) {

if (key == 'z') {

if (m == myMovie2) {

myMovie2.read();

}

}

if (key == 'x') {

if (m == myMovie) {

//myMovie.stop();

myMovie.read();

}

}

}

*/

///////////////////////////////// DRAW /////////////////////////////////// DRAW //////////////

void draw() {

physics.advanceTime( 1.0 );

// background(0, 102, 153); //color blue = color(0, 102, 153);

background (0);

if (slide >0){

pslide=slide;

}

//println (slide);

if (slide==0){

//slide=rslide;

slide=pslide;

}

// myCapture.read();

pushMatrix();

translate(0,0,0);

tint(0, 150, 204, 255);

image(secondClip, 0, 0);

popMatrix();

pushMatrix();

translate(0,0,0);

tint(0, 150, 204, diss);

image (currentClip, xmov, 0);

popMatrix();

///// TNO Pics Buttons // ADD BUTTONS!!!!!!!!!!!!!!!!!!

if (gloveswitch6 == 1) {

//effectSwitch = true;

counter ++;

}

//else {

//counter = 0;

//}

println("counter " + counter);

if (counter == 5) {

counter = 0;

}

if (counter == 1) {

image(hp, 0, 0); // Displays the image from point (0,0)

image(bp, 0, 80);

image(fp, 0, 160);

}

if (counter == 2) {

image(cp, 110, 0);

image(gp, 110, 80);

image(dp, 110, 160);

}

if (counter == 3) {

image(ap, 220, 0);

image (ip,220, 80);

image (jp,220,160);

}

if (counter == 4) {

image(kp, 10, 10);

image (pp,10,160);

image (qp,60, 80);

image (op,120,10);

image (np,180,80);

image (mp,240,160);

image (lp,240,0);

}

if (counter == 5) {

background (0);

image (djdano,20,20);

}

if (key == '1'){

image(hp, 0, 0); // Displays the image from point (0,0)

image(bp, 0, 80);

image(fp, 0, 160);

}

if (key == '2'){

image(cp, 110, 0);

image(gp, 110, 80);

image(dp, 110, 160);

}

//image(e, 0, 160);

if (key == '3'){

image(ap, 220, 0);

image (ip,220, 80);

image (jp,220,160);

}

if (key == '4') {

image(kp, 10, 10);

image (pp,10,160);

image (qp,60, 80);

image (op,120,10);

image (np,180,80);

image (mp,240,160);

image (lp,240,0);

}

if (key == '5') {

background (0);

image (djdano,20,20);

}

// Waveforem effect switch

if (effectSwitch == true) {

currentMovie.read();

//image (currentClip, 0,0);

//drawSpectrum();

drawWriteSamples();

}


////////// Fade Out Transition

if (key == 'l') {

currentMovie.read();

//myMovie.loop();

//myMovie2.read();

//myMovie2.loop();

fadeSwitch = true;

if (fadeSwitch == true) {

fadeOut();

}

}

///////// Wipe Right Transition

if (key == 'k') {

if (wipeLSwitch == true) {

currentMovie.read();

//wipeLSwitch = true;

wipeRight();

}

else {

xmov = 0;

}

}

///////// Wipe Left Transition

if (key == 'j') {

if (wipeLSwitch == true) {

currentMovie.read();

//wipeLSwitch = true;

wipeLeft();

}

else {

xmov = 0;

}

}

///////// Cut Transition

if (key == 'h') {

//Temp = currentClip;

//if (switch2 == true) {

currentMovie.read();

cut();

//} else {

//currentClip = Temp;

//}

}

///////// Video Clips //////////////////

///////// Tunnel Clip

if (key == 'z') {

//image(myMovie2, 0 ,0);

//tint(0, 150, 204, mouseX);

secondClip = currentMovie;

currentMovie = myMovie2;

currentMovie.read();

//currentMovie.loop();

//myCapture.stop();

//myMovie.stop();

//myMovie2.read();

//myMovie2.loop();

}

if (key == 'x') {

//image(myMovie, 0 ,0);

secondClip = currentMovie;

currentMovie = myMovie;

currentMovie.read();

}

///////// Loads Kamel1

if (key == 'c') {

secondClip = currentMovie;

currentMovie = kamel1;

kamel1.read();

}

///////// Loads Kamel2

if (key == 'v') {

secondClip = currentMovie;

currentMovie = kamel2;

kamel2.read();

}

///////// Loads Free1

if (key == 'b') {

secondClip = currentMovie;

currentMovie = free1;

free1.read();

}

///////// Loads Free2

if (key == 'n') {

secondClip = currentMovie;

currentMovie = free2;

free2.read();

}

if (gloveswitch2== 1){ //if (key == 'e') {

background (0);

explode();

thisispressed++;

if (thisispressed == savedFrame.length) {

thisispressed = 0;

}

//tint(0, 150, 204, mouseX);

savedFrame[thisispressed].copy(myCapture,0,0,320,240,0,0,320,240);

savedFrame[thisispressed].updatePixels(); //down arrow

}

//println(secondClip);

//println("Current - " + currentClip + " Second - " + secondClip);

/////////////// ROTATE///////////////////////
if (gloveswitch1 == 1 || key == 'r') { // if (key == 'r') {

// if (switch2 == true) {

zrotate();

//l}

}

/////////Audio Waveform ///////ADD BUTTON!!!!

if (gloveswitch5 == 1 || key == 'm'){ //if (key == 'm'){

currentMovie.read();

effectSwitch = true;

}

////////// Effect Off Button

if (key ==',') {

currentMovie.read();

counter = 0;

effectSwitch = false;

}

/////////// Music On

if (gloveswitch4 == 1 || key == 's') { // if (key == 's') {

effectSwitch = false;

switch2 = false;

counter = 0;

secondClip = myCapture;

camera(width/2.0, height/2.0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0, height/2.0, 0, 0, 1, 0);

//image(currentClip, 0, 0); // QUESTION: How do you clear the stage from previous graphics?

}


if (key == 't') { /// if (key == 't') {

currentMovie.read();

brightnessTracker();

particleDraw();

}

////////////// Buffer

if(keyCode==DOWN) { //put keyCode for UP/DOWN etc

//noTint ();

currentMovie.read();

if (mousePressed == true) {

znew += 5;

}

else if (znew <= 0) {

znew = 0;

}

else {

znew -= 5;

}

newBufferOffset = -myCapture.width/2 + (width-width/30);

float distance = bufferOffset - newBufferOffset;

if( abs(distance) > 0.01 ) {

bufferOffset -= distance/20.0;

bufferOffset = constrain(bufferOffset, -400, 0);

//filter (INVERT);

}

//tint(255, 153);

//image(currentClip,bufferOffset,0);

pushMatrix();

translate(0,0,znew);

tint(0, 150, 204, mouseX);

image(myCapture, bufferOffset, 0);

popMatrix();

//filter (POSTERIZE,5);

}

if (key == 'w') { //if (key == 'w') {

currentMovie.read();

physicsDrawing();

}

if (gloveswitch3 == 1 || key == '.') { //if (key == '.') {

drawPics();

}

}


oid keyPressed() {

if (key == 'o') {

//mySound.play(Ess.FOREVER);

if (mySound.state==Ess.PLAYING) {

mySound.stop();

}

else {

lastCue=-1;

drawBufferLoad=-1;

mySound.play(Ess.FOREVER);

}

}

wipeLSwitch = true;

switch2 = true;

}

void keyReleased(){

// switch3 = false;

wipeLSwitch = false;

switch2 = false;

//xmov = 0;

}

void mousePressed() {


//grabBackground();

// switch1 = true;

}

void mouseReleased() {

for ( int i = 1; i < pin.length; i++ ) {

anchor[i-1].moveTo( anchor[i-1].position().x()-i*50, anchor[i-1].position().y()-i*50, 0 );

}

//switch3 = false;

switch1 = false;

}

void mouseMoved() {

for ( int i = 1; i < pin.length; i++ ) {

pin[i].moveTo( width/2, height/2, 0 );

//pin[i].moveTo( width/2, height/2, 0 );

//pin[i].setVelocity( mouseX, mouseY, 0 );

pin[i].setVelocity( (slide - slide)/3, (slide - slide)/3, 0 ); //pin[i].setVelocity( (mouseX - pmouseX)/3, (mouseY - pmouseY)/3, 0 );

}

}


//////////////////////////*********TRANSITIONS**********///////////////////////////////

////////////////////////////////////Fade Out 'L - Button'/////////////////////////////////////////

void fadeOut() {

//diss = 195;

// while (diss > 0) {

if (fadeSwitch == true) {

// myMovie.play();

diss -= 15;

}

//}

if (diss <= 0) {

//tint(0, 150, 204, diss);

currentClip = secondClip;

diss = 255;

fadeSwitch = false;

}

}

////////////////////////////////////Wipe Left 'J - Button'/////////////////////////////////////////

void wipeLeft() {

//secondClip = currentClip;

//currentClip = secondClip;

//currentClip = blank;

//xmov = 320;

float xmovspeed = 0;

xmovspeed += 5;

xmov -= 20*xmovspeed;

//xmov += 1;

}

/*

if (xmov > 0) {

xmov -= 10;

}

if (xmov <= 0) {

xmov = 0;

*/

////////////////////////////////////Wipe Right 'K - Button'/////////////////////////////////////////

void wipeRight() {

//secondClip = currentClip;

//currentClip = secondClip;

//currentClip = blank;

//xmov = 320;

float xmovspeed = 0;

xmovspeed += 5;

xmov += 20*xmovspeed;

//xmov += 1;

}

////////////////////////////////////Cut 'h' - Button'/////////////////////////////////////////

void cut() {

currentClip = secondClip;

}

//////////////////////////*********EFFECTS**********///////////////////////////////

/////////////////////////////////////PICTURE LOADER/////////////////////////////////

void drawPics() {

float angleIncrements = 2*PI/2; //angle units between each picture, in radians 2*PI = 360 degrees

int radius = 320;

lights();

pushMatrix();

camera(width/2.0*slide/15, height/2.0, slide*-18, width/2.0, height/2.0, 0, 0, 1, 0);

for(int i = 0; inoFill();

translate(0, 0, ((z2+910)-i*280)/3);

float thisAngle = i* angleIncrements/2;

float xpic = radius*cos(thisAngle) + width/2; //width/2-180

float ypic = radius*sin(thisAngle) + height/2-40;

image(thePImageList[i],xpic,ypic+20);

//println("z2 " + z2);

}

//translate(0,0,0);

popMatrix();

}

////////////////////////////////////EXPLODE EFFECT/////////////////////////////////////////

void explode() {

for (int i=0; iif (thisispressed ==i) { //

background (0);

// tint(0, 150, 204, mouseX);

image(savedFrame[i], i*video_width,0);

// filter(POSTERIZE,15);

}

else {

background (0);

//image(currentClip, 0,0); //always put 3

//filter(POSTERIZE,15);

}

for ( int r = 0; r < COLS;r++) {

// Begin loop for rows

for ( int j = 0; j < ROWS;j++) {

int xcell = r*cellsize + cellsize/2; // x position

int ycell = j*cellsize + cellsize/2; // y position

int loc = xcell + ycell*width; // Pixel array location

color c2 = img.pixels[loc]; // Grab the color

// Calculate a z position as a function of mouseX and pixel brightness

float zdis = (slide/ (float) width ) * brightness(img.pixels[loc]) - 100.0f;

// Translate to the location, set fill and stroke, and draw the rect

pushMatrix();

translate(xcell,ycell,zdis);

// tint(0, 150, 204, mouseX);

fill(c2);

noStroke();

rectMode(CENTER);

rect(0,0,cellsize,cellsize);

popMatrix();

}

}

}

}

/////////////////////////////////////PHYSICS DRAWING/////////////////////////////////

void physicsDrawing() {

pushMatrix();

fill(120,100,100,150);

for ( int i = 1; i < pin.length; i++ ) {

ellipse( anchor[i-1].position().x(), anchor[i-1].position().y(), 5, 5 );

ellipse( pin[i].position().x(), pin[i].position().y(), 15, 15 );

line( pin[i].position().x(), pin[i].position().y(), anchor[i-1].position().x(), anchor[i-1].position().y() );

}

if (mousePressed == true) {

for ( int i = 1; i < pin.length; i++ ) {

anchor[i-1].moveTo( anchor[i-1].position().x()+i*50, anchor[i-1].position().y()+i*50, 0 );

}

}

/*

if (slide > 0) {

for ( int i = 1; i < pin.length; i++ ) {

pin[i].moveTo( width/2, height/2, 0 );

//pin[i].moveTo( width/2, height/2, 0 );

//pin[i].setVelocity( mouseX, mouseY, 0 ); vpin[i].setVelocity( (slide - slide)/3, (slide - slide)/3, 0 ); //pin[i].setVelocity( (mouseX - pmouseX)/3, (mouseY - pmouseY)/3, 0 );

}

}

*/

popMatrix();

}

////////////////////////////////////ZROTATE EFFECT/////////////////////////////////////////

void zrotate() {

background(0);

float num = slide/10;

al += 0.01;

if(al > TWO_PI) {

al = 0.0;

}

translate(width/2, height/2,50);

rotateX(al);

rotateY(al*2);

image(currentClip, -rSize, -rSize, rSize*2, rSize*2); vfor (int i=0;i rotateX(al*1.001);

rotateY(al*2.002);

//tint(100,50,6);

image(currentClip, -rSize, -rSize, rSize*2, rSize*2);

}

}

////////////////////////////////////ESS EFFECT///////////////////////////////

//void drawSpectrum() {

// noStroke();

//mySound.loadSpectrum();

// for (int i=0; i<256; i++) {

// float temp = max ( 0, 185 -mySound.spectrum[i]*175); //71 //

//println("temp"+temp);

//rect(i,temp+.100,60,height-temp+.100);

// rect(i,temp+.5,1,height-temp+.5);

//}

//}

void drawWriteSamples() {

stroke(#FF66FF);

//fill(#FF66FF);

// first check to see if we are playing

if (mySound.state==Ess.PLAYING) {

if (mySound.cue!=lastCue) {

// we have a new write buffer to copy

switch (drawBufferLoad) {

case -1:

// fill front of drawBuffer

System.arraycopy(mySound.writeSamples,0,drawBuffer,0,writeSamplesSize);

break;

case 0:

// fill back of drawBuffer

System.arraycopy(mySound.writeSamples,0,drawBuffer,writeSamplesSize,writeSamplesSize);

break;

default:

// shift back of drawBuffer to front and fill back of draw buffer

System.arraycopy(drawBuffer,writeSamplesSize,drawBuffer,0,writeSamplesSize);

System.arraycopy(mySound.writeSamples,0,drawBuffer,writeSamplesSize,writeSamplesSize);

}

drawBufferLoad++;

lastCue=mySound.cue;

drawBufferStartTime=millis();

}

if (drawBufferLoad>0) {

// interpolate between 0 and writeSamplesSize over writeUpdateTime

int interp=(int)(((millis()-drawBufferStartTime)/(float)writeUpdateTime)*writeSamplesSize);

for (int i=0;i<320;i++) {

line(i,100-(mySound.getFrame(drawBuffer,i+interp)*(75.0/32767)),i+1,100-(mySound.getFrame(drawBuffer,i+1+interp)*(75.0/32767)));

}

}

}

else {

fill(#FF66FF);

line(0,100,320,100);

}

}

// clean up Ess before exiting

public void stop() {

Ess.stop();

super.stop();

}

////////////////////////////////////PARTICLE DRAWING EFFECT/////////////////////////////////////////

void particleDraw() {

for (int i = 0; i < a.size(); i++) {

//when something comes out of the arraylist via "get" we have to

//remind ourselves what type it is. In this case, it's an instance of "Particle"

Bits p = (Bits) a.get(i);

p.run();

p.gravity();

p.render();

}

if (mousePressed == true) { // if (mousePressed == true) {

a.add(new Bits());

z += .00;

}

else if (z <= .1) {

z = 0;

}

else {

z -= .1;

}

/*

if (z == 1) {

z = 0;

}

*/

//println(z + "___" );

if (a.size() > 100) {

a.remove(0);

//z -= 1;

//z = 0;

}

}

//tracks the Brightest point

void brightnessTracker() {

float worldRecord = 800.0; //intialize the worldrecord

//Rectangle paddleRect = new Rectangle(0,0,10,10);

for(int j=0; jfor(int i=0; i//get the color of this pixels

//find pixel in linear array using formula: pos = row*rowWidth+column vcolor pix = myCapture.pixels[j*myCapture.width+i];

//find the difference

float diff = abs(targetHue - hue(pix)) + abs(targetSaturation - saturation(pix)) + abs(targetBrightness - brightness(pix));

if (diff< worldRecord){ // if this is closest to our target color

worldRecord = diff;

yFound = j; //mark the spot for drawing it later

xFound = i;

}

}

}

}

//Particle Drawing Class

class Bits {

float rot;

float x;

float y;

float xspeed;

float yspeed;

float sx;

float sy;

float alph = 100;

Bits() {

x = xFound;

y = yFound;

sx = 6;

sy = 6;

xspeed = random(-2,2);

yspeed = random(-5,0);

}

void run() {

x = x + xspeed;

y = y + yspeed;

sx += .3;

sy += .3;

alph -= 2.5;

}

void gravity() {

yspeed += 0.3;

}

void render() {

float rand = random(2,10);

//colorMode(HSB);

color c = color(179,46,45*z+20,alph);

stroke(130,150,35*z+10,alph-20);

//lights();

//translate(x,y,z);

//sphere(sx);

pushMatrix();

fill(c);

ellipse (x+random(-20,30),y+random(-20,30),rand*sx/10,rand*sy/10);

ellipse (x+random(-20,30),y+random(-20,30),rand*sx/10,rand*sy/10);

ellipse (x+random(-20,30),y+random(-20,30),rand*sx/10,rand*sy/10);

popMatrix();

}

}

void serialEvent(Serial p) {

int input = myPort.read();

// if the last thing in was a carriage return, it means that a whole reading is ready

if (input== 13) {

String[] asText = accumulation.split(","); //separate out the reading based on the comma (44)

int[] asNumbers = int(asText); //turn the text reading in to numbers, beware if there is a 13 still attached at the end

//println("accumulation " + accumulation );

if (asNumbers.length >=9){

//scale it a bit based on the empirical readings of this sensor

slide1 = asNumbers[0]/4; //ADC0scale it a bit based on the empirical readings of this sensor

slide = asNumbers[1]/4; //ADC1easy scaling because it is a potentiometer which delivers solid 0-1020

gloveswitch1 = asNumbers[2];

gloveswitch2 =asNumbers[3];

gloveswitch3= asNumbers[4];

gloveswitch4=asNumbers[5];

gloveswitch5=asNumbers[6];

gloveswitch6=asNumbers[7];

gloveswitch7=asNumbers[8];


//println("slide1 " + slide1 + " slide" + slide + " button1 " + gloveswitch1 + " button2 " + gloveswitch2 +" button3 " + gloveswitch3

//+" button4 " + gloveswitch4 + " button5 " + gloveswitch5 + " button6 " + gloveswitch6 + " button7 " + gloveswitch7 );

}

//now that you go a whole reading, clear your accumulation

accumulation = "";

//now send something to satisfy the serin

//in this case I actualy am sending information back but even if you are not just send anything back

//my servo wants numbers 65- 250 and the mouse gives me numbers between 0 and width

int servoRange = 250-65;

float percentageAcross = mouseX/float(width);

int servoOut = int(servoRange*percentageAcross) + 65; //65 * 2 (i multiplied 250*2

myPort.write(servoOut);

//println(servoOut );

}

else{

accumulation= accumulation + char(input); //if you did not hear 13, accumulate

}

} Last updated: 12/12/05