Rtos API example

Embed: (wiki syntax)

« Back to documentation index

MMA8451Q Class Reference

MMA8451Q Class Reference

MMA8451Q accelerometer example include "mbed.h" include "MMA8451Q.h". More...

#include <MMA8451Q.h>

Public Member Functions

 MMA8451Q (PinName sda, PinName scl, int addr)
 MMA8451Q constructor.
 ~MMA8451Q ()
 MMA8451Q destructor.
uint8_t getWhoAmI ()
 Get the value of the WHO_AM_I register.
int16_t getAccX ()
 Get X axis acceleration.
int16_t getAccY ()
 Get Y axis acceleration.
int16_t getAccZ ()
 Get Z axis acceleration.
void getAccAllAxis (int16_t *res)
 Get XYZ axis acceleration.

Detailed Description

MMA8451Q accelerometer example include "mbed.h" include "MMA8451Q.h".

define MMA8451_I2C_ADDRESS (0x1d<<1)

int main(void) { DigitalOut led(LED_GREEN); MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS); printf("WHO AM I: 0x%2X\r\n", acc.getWhoAmI());

while (true) { printf("-----------\r\n"); printf("acc_x: %d\r\n", acc.getAccX()); printf("acc_y: %d\r\n", acc.getAccY()); printf("acc_z: %d\r\n", acc.getAccZ());

wait(1); led = !led; } }

Definition at line 47 of file MMA8451Q.h.


Constructor & Destructor Documentation

MMA8451Q ( PinName  sda,
PinName  scl,
int  addr 
)

MMA8451Q constructor.

Parameters:
sdaSDA pin
sdlSCL pin
addraddr of the I2C peripheral

Definition at line 29 of file MMA8451Q.cpp.

~MMA8451Q (  )

MMA8451Q destructor.

Definition at line 35 of file MMA8451Q.cpp.


Member Function Documentation

void getAccAllAxis ( int16_t *  res )

Get XYZ axis acceleration.

Parameters:
resarray where acceleration data will be stored

Definition at line 55 of file MMA8451Q.cpp.

int16_t getAccX (  )

Get X axis acceleration.

Returns:
X axis acceleration

Definition at line 43 of file MMA8451Q.cpp.

int16_t getAccY (  )

Get Y axis acceleration.

Returns:
Y axis acceleration

Definition at line 47 of file MMA8451Q.cpp.

int16_t getAccZ (  )

Get Z axis acceleration.

Returns:
Z axis acceleration

Definition at line 51 of file MMA8451Q.cpp.

uint8_t getWhoAmI (  )

Get the value of the WHO_AM_I register.

Returns:
WHO_AM_I value

Definition at line 37 of file MMA8451Q.cpp.