Files
Ada_Drivers_Library/examples/MicroBit/accelerometer
Fabien Chouteau f67115ada7 Various Microbit examples fixes and improvements (#367)
* micro:bit examples digital_out: fix resistor value

* micro:bit examples digital_in: fix resistor value

* Update README.md

* Typo

* Typo

* Update README.md

* Update README.md

* Update README.md (#366)
2020-09-18 13:16:44 +02:00
..

Accelerometer Example

In this example we will see how to use the accelerometer of the micro:bit. The accelerometer can, for instance, be used to know which way the micro:bit is oriented.

Code

To get the acceleration value for all axes, we will just call the function MicroBit.Accelerometer.Data. This function returns a record with X, Y and Z field giving the value for each axis.

declare

   Data : MMA8653.All_Axes_Data;
   --  A variable to store the accelerometer data
begin

   --  Read Accelerometer data
   Data := Accelerometer.Data;
end;

We can then use the value in the record to get some information about the orientation of the micro:bit. For example, if the Y value is below -200 the micro:bit is vertical.

Note that the type used to store the values of the accelerometer is declared in the package MMA8653 (the driver), so we have to with and use this package to have access to the operations for this type.

if Data.Y < -200 then
   --  The micro:bit is vertical
end if;