|
CLASS DOCUMENTS
REPORTS & ASSIGNMENTS
CLASS CONTENT
USING THIS SITE
registered authors login here You are: (logout) For more on PMWiki, see pmwiki.org |
Processing Data To Fileby jamie allen Feb 2007
/*
logs data to a file
by Jamie Allen 2007
Created Feb 2007
*/
import processing.serial.*;
Serial myPort; // The serial port
PFont myFont; // The display font:
PrintWriter output;
// initial variables:
int inByte = -1;
int wrote = 0;
int offset = 0;
int offsettext = 25;
void setup()
{
size(100, 100); // window size
// 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, Serial.list()[3], 9600);
output = createWriter("data.txt"); // Create a new file in the sketch directory
}
void draw() {
if (myPort.available() > 0) {
inByte = myPort.read();
output.print(char(inByte));
}
}
void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}
|