We created a simple Android app with Android Studio that uses the an android phone's accelerometer. You will see Baymax on your screen. First, press "start pedometer". As you take a step, Baymax will move side to side, waving in different directions. Our github link to this project is here. Here's how we created it: Download Android StudioDownload Android Studio from this site. Open it and create a new project. Select the basic template. It will now give you some starter code you can modify and add onto. Modify the Main ClassWe will be using Android's built in sensor library in order to signal when a user has taken a step and create a counter for it. There are a few imports you will need, which is on the MainActivity.java file on the Github link. Create the Other ClassesWe will make a total of two classes: the SensorFilter and the StepDetector. We will also be creating an interface called the StepListener. The SensorFilter is responsible for various matrix operations in order to process the raw data that comes from the android's accelerometer. The StepListener does exactly what it's called: begin looking for steps. Lastly, we create the StepDetector, which integrates the sensor data to get the velocity and determine if the movement is indeed a step by checking if it most recently detected pair of velocities differ by the determined threshold. Modify the XML FileWe want to show a different baymax for each step, so we will add in two images of baymax into our xml file. First add the images of baymax into our res/drawables folder. Then add the pertaining code found in Github. Here are the images we used for the baymaxes: The first Baymax will initially start off visible, while the other one remains hidden. When a step is taken, this will switch. You can customize the images as you wish by inserting another set of two images into the drawables folder and replacing every instance of "baymax1" and "baymax2" with the names of your new images. Note: make sure that the file format is a PNG. Build and Run the AppWe can finally build and run our app. It should show up with two buttons at the bottom. One to start the pedometer and one to stop it. It counts the number of steps we have taken while Baymax waves. Enjoy! References:Starter Code for the Pedometer: http://www.gadgetsaint.com/android/create-pedometer-step-counter-android/
Images of Baymax: https://ppc.fandom.com/wiki/Mini/Big_Hero_6?file=Baymax.png |
Photo used under Creative Commons from Ashwin Kumar