- Using the Accelerometer to make sure the user is holding the phone flat, vibrating if it isn't
- Reading whether the shot is to be a hit or miss to the user.
A lot of modern phones running the android operating system contain accelerometers within them, they also contain a vibrate function normally used when the user wants the phone to be quiet.
The android website contains an example of using the accelerometer:
http://developer.android.com/resources/samples/AccelerometerPlay/src/com/example/android/accelerometerplay/AccelerometerPlayActivity.html
There is also the source code for using the Vibrate function which is found here:
http://developer.android.com/reference/android/os/Vibrator.html
When the activity is created, a new sensor manager is set up which 'listens' for a change in the sensor values, the threshold was set as 1 or -1 in both the x and y direction for the vibrate function to be turned on, the implemented code is shown below:
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
v.cancel();
// check sensor type
if(event.sensor.getType()==Sensor.TYPE_ACCELEROMETER){
// assign directions
float x=event.values[0];
float y=event.values[1];//Measure the Acceleromter in the X and Y direction
if(x>1||x<-1||y>1||y<-1){//Occurrs if they Exceed defined values
v.vibrate(1000);//Makes Phone Vibrate for 1 Second
}
Chris
No comments:
Post a Comment