|
CLASS DOCUMENTS
REPORTS & ASSIGNMENTS
CLASS CONTENT
USING THIS SITE
registered authors login here You are: (logout) For more on PMWiki, see pmwiki.org |
Assignment 1 Processing Code
import processing.serial.*;
Serial myPort; // The serial port
int[] serialInArray = new int[3]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we
receive
// initial variables:
int i = 1; // counter
int inByte = -1; // data from serial port
int firstread = 149;
int xpos = 0;
void setup () {
size(400, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[2], 9600);
background(0);
}
void draw () {
while (myPort.available() > 0) {
processByte(myPort.read());
}
void drawGraph () {
int valueToGraph = 0;
valueToGraph = xpos;
stroke(255,0,0);
curve(120, height+abs((valueToGraph-firstread-30) *2), 0, height-30, width, height-30, 120, height + abs((valueToGraph-firstread-30)*2));
if (i > 1) {
i = 0;
background(0);
}
else {
i++;
}
}
void processByte( int inByte) {
serialInArray[serialCount] = inByte;
xpos = serialInArray[0];
drawGraph();
serialCount = 0;
}
|