Getting acceleration on axis
There are several registers used to get acceleration on three axis. These registers are defined in the Waspmote ACC library as constants, that can be modified by the user if required. However, these definitions should not be modified unless registers addresses change in future accelerometer revisions.
The accelerometer can use three scales: ±2g, ±4g and ±8g. See section "Initializing the accelerometer" for more information. The following examples have been tested using the ±2g scale.
The
getX()
function checks accelerometer's acceleration on X axis. The value returned is defined in mG units.It returns the combined contents of data registers
outXhigh
and outXlow
as an integer.Since it calls
readRegister()
, it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING
in case there was an error communicating to the register.Example of use:
{
int accX;
accX = ACC.getX();
}
The
getY()
function checks accelerometer's acceleration on Y axis. The value returned is defined in mG units.It returns the combined contents of data registers
outYhigh
and outYlow
as an integer.Since it calls
readRegister()
, it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING
in case there was an error when communicating to the register.Example of use:
{
int accY;
accY = ACC.getY();
}
The
getZ()
function checks accelerometer's acceleration on Z axis. The value returned is defined in mG units.It returns the combined contents of data registers
outZhigh
and outZlow
as an integer.Since it calls
readRegister()
, it will not activate any flags by itself, but the other functions will activate ACC_ERROR_READING
in case there was an error when communicating to the register.Example of use:
{
int accZ;
accZ = ACC.getZ();
}
Last modified 2yr ago