Forked MMA7660 , extend implementation by using i2c asynch API, to sleep while waiting for transfer -> blocking asynch :-D

Fork of MMA7660 by Erik -

Embed: (wiki syntax)

« Back to documentation index

MMA7660 Class Reference

MMA7660 Class Reference

An interface for the MMA7660 triple axis accelerometer. More...

#include <MMA7660.h>

Public Types

enum  Orientation
 

The 6 different orientations and unknown.

More...

Public Member Functions

 MMA7660 (PinName sda, PinName scl, bool active=true, bool asynch=false)
 Creates a new MMA7660 object.
bool testConnection (void)
 Tests if communication is possible with the MMA7660.
void setActive (bool state)
 Sets the active state of the MMA7660.
void readData (int *data)
 Reads acceleration data from the sensor.
float x (void)
 Get X-data.
float y (void)
 Get Y-data.
float z (void)
 Get Z-data.
void setSampleRate (int samplerate)
 Sets the active samplerate.
Orientation getSide (void)
 Returns if it is on its front, back, or unknown side.
Orientation getOrientation (void)
 Returns if it is on it left, right, down or up side.

Detailed Description

An interface for the MMA7660 triple axis accelerometer.

 //Uses the measured z-acceleration to drive leds 2 and 3 of the mbed

 #include "mbed.h"
 #include "MMA7660.h"

 MMA7660 MMA(p28, p27);

 DigitalOut connectionLed(LED1);
 PwmOut Zaxis_p(LED2);
 PwmOut Zaxis_n(LED3);

 int main() {
     if (MMA.testConnection())
         connectionLed = 1;

     while(1) {
         Zaxis_p = MMA.z();
         Zaxis_n = -MMA.z();
     }

 }

Definition at line 63 of file MMA7660.h.


Member Enumeration Documentation

The 6 different orientations and unknown.

Up & Down = X-axis Right & Left = Y-axis Back & Front = Z-axis

Definition at line 74 of file MMA7660.h.


Constructor & Destructor Documentation

MMA7660 ( PinName  sda,
PinName  scl,
bool  active = true,
bool  asynch = false 
)

Creates a new MMA7660 object.

Parameters:
sda- I2C data pin
scl- I2C clock pin
active- true (default) to enable the device, false to keep it standby
asynch- use asynch i2c - the API is blocking which does not break the current app

Definition at line 3 of file MMA7660.cpp.


Member Function Documentation

MMA7660::Orientation getOrientation ( void   )

Returns if it is on it left, right, down or up side.

This is read from MMA7760s registers, page 12 of datasheet

Parameters:
return- Left, Right, Down, Up or Unknown orientation

Definition at line 142 of file MMA7660.cpp.

MMA7660::Orientation getSide ( void   )

Returns if it is on its front, back, or unknown side.

This is read from MMA7760s registers, page 12 of datasheet

Parameters:
return- Front, Back or Unknown orientation

Definition at line 130 of file MMA7660.cpp.

void readData ( int *  data )

Reads acceleration data from the sensor.

When the parameter is a pointer to an integer array it will be the raw data. When it is a pointer to a float array it will be the acceleration in g's

Parameters:
data- pointer to array with length 3 where the acceleration data will be stored, X-Y-Z

Definition at line 54 of file MMA7660.cpp.

void setActive ( bool  state )

Sets the active state of the MMA7660.

Note: This is unrelated to awake/sleep mode

Parameters:
state- true for active, false for standby

Definition at line 38 of file MMA7660.cpp.

void setSampleRate ( int  samplerate )

Sets the active samplerate.

The entered samplerate will be rounded to nearest supported samplerate. Supported samplerates are: 120 - 64 - 32 - 16 - 8 - 4 - 2 - 1 samples/second.

Parameters:
samplerate- the samplerate that will be set

Definition at line 106 of file MMA7660.cpp.

bool testConnection ( void   )

Tests if communication is possible with the MMA7660.

Because the MMA7660 lacks a WHO_AM_I register, this function can only check if there is an I2C device that responds to the MMA7660 address

Parameters:
return- true for successfull connection, false for no connection

Definition at line 20 of file MMA7660.cpp.

float x ( void   )

Get X-data.

Parameters:
return- X-acceleration in g's

Definition at line 90 of file MMA7660.cpp.

float y ( void   )

Get Y-data.

Parameters:
return- Y-acceleration in g's

Definition at line 95 of file MMA7660.cpp.

float z ( void   )

Get Z-data.

Parameters:
return- Z-acceleration in g's

Definition at line 100 of file MMA7660.cpp.