Program with an accelerometer
in
Core Library Questions
•
1 year ago
Hi Everybody !
I'm a french student and i love programation with processing, but i have a problem.
I want to transmite the x,y,z position to my accelero on my pc with a program whitch draw curves.
I have a problem, i have the 3 curves but they represent the same axes !
I want a curve for x, a curve for y and a curve for z...
Someone can help me ?
__________________________________
import processing.serial.*;
Serial myPort;
int xPos = 1;
void setup () {
size(1200, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
background(0);
}
void draw () {
}
void serialEvent (Serial myPort) {
float inByte;
String inString = myPort.readStringUntil('\n');
if (inString != null) {
String[] tokens = inString.split(",");
if (tokens.length == 4) {
inString = trim(inString);
// rouge
inByte = int(tokens[0]);
inByte = map(inByte, 0, 1023, 0, height);
stroke(255,0,0);
line(xPos, height, xPos, height - inByte);
// vert
inByte = int(tokens[1]);
inByte = map(inByte, 0, 1023, 0, height);
stroke(0,255,0);
line(xPos+400, height, xPos+400, height - inByte);
// bleu
inByte = int(tokens[2]);
inByte = map(inByte, 0, 1023, 0, height);
stroke(0,0,255);
line(xPos+800, height, xPos+800, height - inByte);
if (xPos >= 400) {
xPos = 0;
background(0);
} else {
xPos++;
}
}
}
}
Ty :D
I'm a french student and i love programation with processing, but i have a problem.
I want to transmite the x,y,z position to my accelero on my pc with a program whitch draw curves.
I have a problem, i have the 3 curves but they represent the same axes !
I want a curve for x, a curve for y and a curve for z...
Someone can help me ?
__________________________________
import processing.serial.*;
Serial myPort;
int xPos = 1;
void setup () {
size(1200, 300);
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil('\n');
background(0);
}
void draw () {
}
void serialEvent (Serial myPort) {
float inByte;
String inString = myPort.readStringUntil('\n');
if (inString != null) {
String[] tokens = inString.split(",");
if (tokens.length == 4) {
inString = trim(inString);
// rouge
inByte = int(tokens[0]);
inByte = map(inByte, 0, 1023, 0, height);
stroke(255,0,0);
line(xPos, height, xPos, height - inByte);
// vert
inByte = int(tokens[1]);
inByte = map(inByte, 0, 1023, 0, height);
stroke(0,255,0);
line(xPos+400, height, xPos+400, height - inByte);
// bleu
inByte = int(tokens[2]);
inByte = map(inByte, 0, 1023, 0, height);
stroke(0,0,255);
line(xPos+800, height, xPos+800, height - inByte);
if (xPos >= 400) {
xPos = 0;
background(0);
} else {
xPos++;
}
}
}
}
Ty :D
1