Created
January 5, 2013 16:24
-
-
Save mlashcorp/4462330 to your computer and use it in GitHub Desktop.
Android accelerometer polling, just the creation and update portions. Updated the class to implement SensorEventListener, since SensorListener is deprecated
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
sm = (SensorManager) getSystemService(SENSOR_SERVICE); | |
accell = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); | |
setContentView(R.layout.activity_main); | |
xacc = (TextView) findViewById(R.id.xvalue); | |
yacc = (TextView) findViewById(R.id.yvalue); | |
zacc = (TextView) findViewById(R.id.zvalue); | |
} | |
public void onSensorChanged(SensorEvent event) { | |
synchronized (this) { | |
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { | |
xacc.setText("Accel X: " + event.values[0]); | |
yacc.setText("Accel Y: " + event.values[1]); | |
zacc.setText("Accel Z: " + event.values[2]); | |
} | |
if(logging) | |
data.add(event.values); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment