Hi i wanna use ketai lib to pop out the values of accelX and use it move a rectangle box based on the TILT of the phone. I used the following code and tried to move the box, but it does not look stable because the value of accel keeps on changes even when i try to keep the phone stable.
import ketai.sensors.*;
KetaiSensor sensor;
float accelerometerX, accelerometerY, accelerometerZ;
float val;
void settings()
{
fullScreen();
}
void setup()
{
sensor = new KetaiSensor(this);
sensor.start();
// orientation(LANDSCAPE);
textAlign(CENTER, CENTER);
textSize(12);
}
void draw()
{
background(0);
text("Accelerometer: \n" +
"x: " + nfp(accelerometerX, 1, 3) + "\n" +
"y: " + nfp(accelerometerY, 1, 3) + "\n" +
"z: " + nfp(accelerometerZ, 1, 3), 0, 0, width, height);
val = map (accelerometerX,-6,+6,0,width);
rect (val,height-50,100,10);
frameRate(30);
}
void onAccelerometerEvent(float x, float y, float z)
{
accelerometerX = x;
accelerometerY = y;
accelerometerZ = z;
}
Pls help me!!
Thanks!