Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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) | |
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
enum Orientation |
Constructor & Destructor Documentation
MMA7660 | ( | PinName | sda, |
PinName | scl, | ||
bool | active = true |
||
) |
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
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 122 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 109 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 34 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 19 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 86 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 11 of file MMA7660.cpp.
float x | ( | void | ) |
float y | ( | void | ) |
float z | ( | void | ) |
Generated on Tue Jul 12 2022 14:26:50 by
