An input/output controller for virtual pinball machines, with plunger position tracking, accelerometer-based nudge sensing, button input encoding, and feedback device control.

Dependencies:   USBDevice mbed FastAnalogIn FastIO FastPWM SimpleDMA

Embed: (wiki syntax)

« Back to documentation index

MMA8451Q Class Reference

MMA8451Q Class Reference

MMA8451Q accelerometer example. More...

#include <MMA8451Q.h>

Public Member Functions

 MMA8451Q (PinName sda, PinName scl, int addr)
 MMA8451Q constructor.
 ~MMA8451Q ()
 MMA8451Q destructor.
void init ()
 Reset the accelerometer hardware and set our initial parameters.
void standby ()
 Enter standby mode.
void active ()
 Enter active mode.
uint8_t getWhoAmI ()
 Get the value of the WHO_AM_I register.
float getAccX ()
 Get X axis acceleration.
float getAccY ()
 Get Y axis acceleration.
void getAccXY (float &x, float &y)
 Read an X,Y pair.
void getAccXYZ (float &x, float &y, float &z)
 Read X,Y,Z.
float getAccZ ()
 Get Z axis acceleration.
void getAccAllAxis (float *res)
 Get XYZ axis acceleration.
void setInterruptMode (int pin)
 Set interrupt mode.

Detailed Description

MMA8451Q accelerometer example.

 #include "mbed.h"
 #include "MMA8451Q.h"
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 
 int main(void) {
 
 MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
 PwmOut rled(LED_RED);
 PwmOut gled(LED_GREEN);
 PwmOut bled(LED_BLUE);
 
     while (true) {       
         rled = 1.0 - abs(acc.getAccX());
         gled = 1.0 - abs(acc.getAccY());
         bled = 1.0 - abs(acc.getAccZ());
         wait(0.1);
     }
 }

Definition at line 49 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 67 of file MMA8451Q.cpp.

~MMA8451Q (  )

MMA8451Q destructor.

Definition at line 114 of file MMA8451Q.cpp.


Member Function Documentation

void active (  )

Enter active mode.

Definition at line 163 of file MMA8451Q.cpp.

void getAccAllAxis ( float *  res )

Get XYZ axis acceleration.

Parameters:
resarray where acceleration data will be stored

Definition at line 226 of file MMA8451Q.cpp.

float getAccX (  )

Get X axis acceleration.

Returns:
X axis acceleration

Definition at line 180 of file MMA8451Q.cpp.

void getAccXY ( float &  x,
float &  y 
)

Read an X,Y pair.

Definition at line 184 of file MMA8451Q.cpp.

void getAccXYZ ( float &  x,
float &  y,
float &  z 
)

Read X,Y,Z.

This is the most efficient way to fetch all of the axes at once, since it fetches all three in a single I2C transaction.

Definition at line 199 of file MMA8451Q.cpp.

float getAccY (  )

Get Y axis acceleration.

Returns:
Y axis acceleration

Definition at line 218 of file MMA8451Q.cpp.

float getAccZ (  )

Get Z axis acceleration.

Returns:
Z axis acceleration

Definition at line 222 of file MMA8451Q.cpp.

uint8_t getWhoAmI (  )

Get the value of the WHO_AM_I register.

Returns:
WHO_AM_I value

Definition at line 174 of file MMA8451Q.cpp.

void init (  )

Reset the accelerometer hardware and set our initial parameters.

Definition at line 74 of file MMA8451Q.cpp.

void setInterruptMode ( int  pin )

Set interrupt mode.

'pin' is 1 for INT1_ACCEL (PTA14) and 2 for INT2_ACCEL (PTA15). The caller is responsible for setting up an interrupt handler on the corresponding PTAxx pin.

Definition at line 116 of file MMA8451Q.cpp.

void standby (  )

Enter standby mode.

Definition at line 147 of file MMA8451Q.cpp.