I am trying to plot a graph on processing but I'm having challenges going about it. The processing sketch below does work for plotting only one axis, and I'm trying to plot all three axis on the same sketch. Does anyone have an idea on how I could go about it. Below are the Arduino and Processing sketches.
Arduino
AcceleroMMA7361 ski;
int x;
int y;
int z;
void setup()
{
Serial.begin(115200);
ski.begin(13, 12,11,10, A0, A1, A2);
ski.setARefVoltage(3.3);
ski.setSensitivity(HIGH);
ski.calibrate();
}
void loop()
{
x = ski.getXRaw();
y = ski.getYRaw();
z = ski.getZRaw();
//Serial.print("\nx: ");
Serial.println(x);
//Serial.print("\ty: ");
//Serial.print(y);
//Serial.print("\tz: ");
//Serial.print(z);
delay(10); //(make it readable)
}//End of Arduino Sketch
Processing
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
float fValue;
boolean newVal = false;
void setup () {
size(800, 630);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 115200);
myPort.bufferUntil('\n');
background(2);
stroke(127, 34, 255);
}
void draw () {
if (newVal) {
line(xPos, height, xPos, height - fValue);
if (++xPos >= width) {
xPos = 0;
background(2);
}
newVal = false;
}
}
void serialEvent (Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
fValue = float(inString);
fValue = map(fValue, 0, 1023, 0, height);
newVal = true;
}
}