Thanks for your advice.I made the following changes to the program.I used accelerometer data.The arm is shaking according to accelerometer data but its not showing a fix position as the accelerometer data is also fluctuation.what changes should i make to stabilize the arm?
float p, q;
float angle1 = 0.0;
float angle2 = 0.0;
float segLength = 100;
import oscP5.*;
import netP5.*;
OscP5 osc;
void setup() {
osc = new OscP5(this, 10000);
osc.plug(this, "shake", "/accelerometer");
size(640, 360);
strokeWeight(30);
stroke(255, 160);
p = width * 0.3;
q = height * 0.5;
}
void draw() {
}
void shake(float x, float y, float z){
background(0);
println(x+"," + y+","+ z);
angle1 = 0;
angle2 = (x);
pushMatrix();
segment(p, q, angle1);
segment(segLength, 0, angle2);
popMatrix();
}
void segment(float p, float q, float a) {
translate(p, q);
rotate(a);
line(0, 0, segLength, 0);
}