In this session today we will create an app using accelerometer which will respond to X ,Y and Z axis when the mobile phone is tilted in the respective angles.
- To work on accelerometer follow the steps given below :
- First of all download and install the Xampp server in your machine or if it is already installed then go to Xampp -> htdocs folder and in htdocs folder create a new folder say Accelerometer .
- In Accelerometer folder create new file say index.html .
- Now open this index.html file with Notepad++ or any other text editor and write the following code :
- Here is the screen shot of Notepad++ window :
- Now save your file and start your apache and MySQL modules from XAMPP Control Pannel.
- Now lets execute our app on ripple emulator .
- Go to emulate.phonegap.com then you will get the following window:
- Click on the Get Ripple Emulator button then you will be navigated to the following window :
- Now click on the FREE button as shown by the red arrow in the above image and you will get the following window :
- Now click on the ADD button and the Ripple Emulator will get added to the browser :
- Now open up the browser and enter the url as localhost/Accelerometer(i.e your folder name in htdocs) and enable the ripple emulator as shown in the image below :
- After clicking the enable button you will get the ripple emulator as shown below: where you have to click on the dropdown button on the left hand side as shown by the red arrow,similarly drag and rotate the mobile icon indicated by the red arrow to get the output for X , Y , Z axis:
- So as you drag and rotate the mobile icon which is located at the left handside you will get the readings at the X , Y , Z axis as shown in the image below :
- Thus we have successfully implemented accelerometer app with phonegap .