Processing program using OSC messages

I added the codes to the program. Its working fine. Even though it is not 100% stable.My idea is to rotate the arm according to the angle created by the phone during tilting.can i do it with the accelerometer data?I tried by using rotateX(x) command.But i think it is not the right idea.

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(x*2.5,y*2.5,z*2.5);

  println(x+"," + y+","+ z);
  x = y;
  x = lerp(x, y, 0.09);
  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);
}