Using the Pedometer in MIT App Inventor
The pedometer uses the phones motion sensors (accelerometers) to identify when the phone (or tablet) is being carried by someone that is walking – and uses this to measure the number of steps you take as you walk. When calibrated to the length of your stride, the pedometer provides a way to estimate the distance you have traveled.
The pedometer is so simple to use, I put this example together while eating lunch today.
This is a simple program!
To use this app, enter your stride length in meters. For illustration, I set the stride length to 1/2 meter or 0.5, as seen in this screen shot:
Press the Start measuring steps button to activate the pedometer and then start walking with your phone. You will soon see the Elapsed distance value increase as you move around.
Using the Designer, set a Horizontal layout at top, and add a Label and set its text to Set stride length:, then add a Textbox to its right.
Add another Horizontal layout and add two buttons. Set one for the Start measuring button and the other for the Stop measuring button.
The next line is optional – a label has been added which is used to display the WalkingStep event status.
Then add another Horizontal layout with two labels – one to say “Elapsed distance:” and the second to display the distance traveled.
Don’t forget to add the Pedometer component! The Pedometer is located in the Sensors section of the Palette, and when dropped on the Designer View, appears as a non-visible component below the screen area.
The components are labeled as shown here:
The NumbersOnly property checkbox of txtStrideLength is checked to limit the input to numeric values.
Setting up the Designer View is harder than writing the app!
The Pedometer is started by – surprise – calling its .Start method.
The Pedometer is stopped by calling its .Stop method.
The .Reset method resets the distance counters to zero.
As you walk, the Pedometer component generates two events – either SingleStep or WalkStep. The distance parameter holds the estimated distance traveled and is the same as the Pedometer.Distance property.
Access the source file at the MIT App Inventory Gallery.
In addition to hundreds of posts and examples on this blog, I have several e-books available from Google Books, Amazon and other outlets. The books cover topics that are far too large to cover in blog posts, especially for Volume 3 – Databases and Files and Volume 4 – Graphics, Animation and Charts. Volumes 1 and 2 are intended for those just starting out with App Inventor.
Visit the books page for details on each book, sample chapters, where to buy – all are very inexpensive.
Also, use the Search box in the left column of this web site to look for other examples to help you with your App Inventor programming!