MSS / MMA8452Q

Dependents:   test_MMA8452Q HelloWorld testSensor

Embed: (wiki syntax)

« Back to documentation index

MMA8452Q Class Reference

MMA8452Q Class Reference

MMA8452Q accelerometer example. More...

#include <MMA8452Q.h>

Public Member Functions

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

Detailed Description

MMA8452Q accelerometer example.

#include "mbed.h"
#include "MMA8452Q.h"

#if defined (TARGET_KL25Z)
#define PIN_SCL  PTE1
#define PIN_SDA  PTE0
#elif defined (TARGET_KL46Z)
#define PIN_SCL  PTE1
#define PIN_SDA  PTE0
#elif defined (TARGET_K64F)
#define PIN_SCL  PTE24
#define PIN_SDA  PTE25
#elif defined (TARGET_K22F)
#define PIN_SCL  PTE1
#define PIN_SDA  PTE0
#elif defined (TARGET_KL05Z)
#define PIN_SCL  PTB3
#define PIN_SDA  PTB4
#elif define (TARGET_F411RE)
#define PIN_SCL  PB_8
#define PIN_SDA  PB_9
#else
 #error TARGET NOT DEFINED
#endif
 
#define MMA8452_I2C_ADDRESS (0x1d)
 
int main(void) {
     float x, y, z ;

     MMA8452Q acc(PIN_SDA, PIN_SCL, MMA8452_I2C_ADDRESS);
 
     while (true) {       
         x = acc.getAccX() ;
         y = acc.getAccY() ;
         z = acc.getAccZ() ;
         printf("X[%.2f] Y[%.2f] Z[%.2f]\n",x, y, z) ;
         wait(0.1);
    }
}

Definition at line 73 of file MMA8452Q.h.


Constructor & Destructor Documentation

MMA8452Q ( PinName  sda,
PinName  scl,
int  addr 
)

MMA8452Q constructor.

Parameters:
sdaSDA pin
sdlSCL pin
addraddr of the I2C peripheral

Definition at line 69 of file MMA8452Q.cpp.

~MMA8452Q (  )

MMA8452Q destructor.

Definition at line 75 of file MMA8452Q.cpp.


Member Function Documentation

void getAccAllAxis ( float *  res )

Get XYZ axis acceleration.

Parameters:
resarray where acceleration data will be stored

Definition at line 95 of file MMA8452Q.cpp.

float getAccX (  )

Get X axis acceleration.

Returns:
X axis acceleration

Definition at line 83 of file MMA8452Q.cpp.

float getAccY (  )

Get Y axis acceleration.

Returns:
Y axis acceleration

Definition at line 87 of file MMA8452Q.cpp.

float getAccZ (  )

Get Z axis acceleration.

Returns:
Z axis acceleration

Definition at line 91 of file MMA8452Q.cpp.

uint8_t getWhoAmI (  )

Get the value of the WHO_AM_I register.

Returns:
WHO_AM_I value

Definition at line 77 of file MMA8452Q.cpp.