Changeing the frequency of the sine wave using a Bend sensor
From Wiki
import krister.Ess.*;
AudioChannel myChannel;
SineWave myWave, myWaveHigh,myWaveLow;
import processing.serial.*;
Serial myPort; // The serial port
PFont font;
// initial variables:
int i = 1; // counter
int inByte = -1; // data from serial port
long fre;
void setup () {
size(500, 650); // window size
font = loadFont("ArialMT-72.vlw");
// List all the available serial ports
println(Serial.list());
// I know that the third port in the serial list on my mac // is always my Keyspan adaptor, so I open Serial.list()[2]. // Open whatever port is the one you're using.
myPort = new Serial(this,"COM11", 9600);
// set inital background:
background(255);
// start up Ess
Ess.start(this);
// create a new AudioChannel
myChannel=new AudioChannel();
// set the channel size to 5 seconds
myChannel.initChannel(myChannel.frames(10000));
// generate 3 seconds of a soft sine wave
//if(int(inByte)>= 100){
//}
}
void draw () {
if (myPort.available() > 0) {
inByte = myPort.read();
println(inByte);
serialEvent();
}
fre = inByte;
}
void serialEvent () {
// draw the line:
stroke(0,0,255);
line(i, height, i, height - inByte);
textFont(font, 72);
fill(255);
stroke(255);
rect(0, 0, width, 70);
fill(0);
text(inByte, 125, 60);
// at the edge of the screen, go back to the beginning:
if (i >= width) {
i = 0;
background(255);
}
else {
i++;
}
myWave=new SineWave(inByte*3,1);
myWave.generate(myChannel,0,myChannel.frames(10000));
// play
myChannel.play();
println(inByte);}
