A three-axis accelerometer on the Badge WX is useful for the following: motion detector, pedometer, slope measurement, activating an alarm, and games. In a static position the accelerometer measures incline on X/Y axis to 100%. Short movements are also captured up to ±1.5 g. Reading the accelerometer is done with a few blocks:
The Accelerometer Bubble Display example program positions the bubble in a two-axis graph. Start by laying the badge flat on the table and then tilt it different directions. The X and Y percentage incline is displayed in the upper and lower left sides of the OLED, respectively.
The program pseudocode could best be described like this:
-
Start a processor to continually obtain the x-axis and y-axis values;
-
Create a loop which repeats the following:
-
Draw circles and lines on OLED (they need to be redrawn as they are erased by the bubble’s movements);
-
Draw text labels and values on OLED (also need to be redrawn if erased by the bubble);
-
Erase and draw the bubble (if not erased you’ll fill the screen with a “snake”)
-
This program certainly has room for improvements, too. Drawing shapes and lines on the OLED consumes memory and is quite slow. Redrawing of text labels and values slows it down even further. The code could be modified to run faster. Or, simple forget the bubble display and create a snake game!
- RIGHT CLICK the file and choose Save File As.
- Save the file to your desktop.
- Open your BlocklyProp Launcher and connect your Badge WX to your USB port.
- In the top right corner of the screen, click Open.
- Click Choose File, and select the file you saved to your desktop.