Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onSensorChanged(SensorEvent event) {
- // TODO Auto-generated method stub
- // In this example, alpha is calculated as t / (t + dT),
- // where t is the low-pass filter's time-constant and
- // dT is the event delivery rate.
- final float alpha = (float) 0.8;
- Log.v(SENSOR_SERVICE, "on sensor change");
- // Isolate the force of gravity with the low-pass filter.
- gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
- gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
- gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
- // Show changes on screen.
- TextView textView = (TextView) findViewById(R.id.axl_x);
- textView.setText(Float.toString(gravity[0]));
- textView = (TextView) findViewById(R.id.axl_y);
- textView.setText(Float.toString(gravity[1]));
- textView = (TextView) findViewById(R.id.axl_y);
- textView.setText(Float.toString(gravity[2]));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement