Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. public void onSensorChanged(SensorEvent event) {
  2.         // TODO Auto-generated method stub
  3.         // In this example, alpha is calculated as t / (t + dT),
  4.           // where t is the low-pass filter's time-constant and
  5.           // dT is the event delivery rate.
  6.  
  7.           final float alpha = (float) 0.8;
  8.          
  9.           Log.v(SENSOR_SERVICE, "on sensor change");
  10.        
  11.         // Isolate the force of gravity with the low-pass filter.
  12.           gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
  13.           gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
  14.           gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
  15.  
  16.      
  17.         // Show changes on screen.
  18.           TextView textView = (TextView) findViewById(R.id.axl_x);
  19.           textView.setText(Float.toString(gravity[0]));
  20.  
  21.           textView = (TextView) findViewById(R.id.axl_y);
  22.           textView.setText(Float.toString(gravity[1]));
  23.          
  24.  
  25.           textView = (TextView) findViewById(R.id.axl_y);
  26.           textView.setText(Float.toString(gravity[2]));
  27.        
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement