Processing code:
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(800, 800);
background(255, 204, 0);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, "/dev/tty.usbserial-FTEZU8DO", 115200);
}
void draw()
{
int v1 = 0, v2 = 0, v3 = 0, v4 = 0;
while (true) {
if (myPort.available() > 0) {
v1 = v2;
v2 = v3;
v3 = v4;
v4 = myPort.read();
//println(v4);
}
if (v1 == 1 && v2 == 2 && v3 == 3 && v4 == 4) {
break;
}
background(255, 204, 0);
}
while (myPort.available() < 8) {}
int up_low, up_high;
int up = myPort.read();
//up_low = myPort.read();
//up_high = myPort.read();
//int up = up_high * 256 + up_low;
println(up);
triangle(20, 10,(20+(up*2)), 10, (((10+(2*up))/2)), (1.7*up*2));
//background(map(up, 0, 300, 0, 255));
//delay(60);
}
|