API for the MMA7660 I2C 3-Axis Digital Accelerometer.
More...
UPM module for the MMA7660 I2C 3-axis digital accelerometer. This device supports a variety of capabilities, including the generation of interrupts for various conditions, tilt and basic gesture detection, and X/Y/Z-axis measurements of g-forces being applied (up to 1.5g)
This module was tested with the Grove 3-Axis Digital Accelerometer (1.5g)
MMA7660_DEFAULT_I2C_ADDR);
while (shouldRun)
{
float ax, ay, az;
cout << "Acceleration: x = " << ax
<< "g y = " << ay
<< "g z = " << az
<< "g" << endl;
cout << endl;
usleep(500000);
}
MMA7660 |
( |
int |
bus, |
|
|
uint8_t |
address = MMA7660_DEFAULT_I2C_ADDR |
|
) |
| |
MMA7660 constructor
- Parameters
-
bus | I2C bus to use |
address | Address for this sensor; default is 0x55 |
bool writeByte |
( |
uint8_t |
reg, |
|
|
uint8_t |
byte |
|
) |
| |
Writes a byte value into a register
- Parameters
-
reg | Register location to write into |
byte | Byte to write |
- Returns
- True if successful
uint8_t readByte |
( |
uint8_t |
reg | ) |
|
Reads a byte value from a register
- Parameters
-
reg | Register location to read from |
- Returns
- Value in a specified register
void getRawValues |
( |
int * |
x, |
|
|
int * |
y, |
|
|
int * |
z |
|
) |
| |
Reads the current value of conversion
- Parameters
-
x | Returned x value |
y | Returned y value |
z | Returned z value |
void getAcceleration |
( |
float * |
ax, |
|
|
float * |
ay, |
|
|
float * |
az |
|
) |
| |
Gets the computed acceleration
- Parameters
-
ax | Returned computed acceleration of the X-axis |
ay | Returned computed acceleration of the Y-axis |
az | Returned computed acceleration of the Z-axis |
int getVerifiedAxis |
( |
MMA7660_REG_T |
axis | ) |
|
Reads an axis, verifying its validity. The value passed must be one of REG_XOUT, REG_YOUT, or REG_ZOUT.
- Parameters
-
- Returns
- Axis value
uint8_t getVerifiedTilt |
( |
| ) |
|
Reads the tilt register, verifying its validity
- Returns
- Tilt value
Puts the device in the active mode. In this mode, register writes are not allowed. Place the device in the standby mode before attempting to write registers.
Puts the device in the standby (power saving) mode. Note: when in the standby mode, there is no valid data in the registers. In addition, the only way to write a register is to put the device in the standby mode.
uint8_t tiltBackFront |
( |
| ) |
|
Reads tiltBackFront bits
The value returned is one of the MMA7660_TILT_BF_T values
- Returns
- Bits corresponding to the BackFront tilt status
uint8_t tiltLandscapePortrait |
( |
| ) |
|
Reads tiltLandscapePortrait bits
The value returned is one of the MMA7660_TILT_LP_T values
- Returns
- Bits corresponding to the LandscapePortrait tilt status
Reads the tiltTap status
- Returns
- True if a tap is detected
Reads the tiltShake status
- Returns
- True if a shake is detected
Uninstalls the previously installed ISR
bool setInterruptBits |
( |
uint8_t |
ibits | ) |
|
Enables interrupt generation based on passed interrupt bits. The bits are a bitmask of the requested MMA7660_INTR_T values. Note: the device must be in the standby mode to set this register.
- Parameters
-
ibits | Sets the requested interrupt bits |
- Returns
- True if successful
bool setSampleRate |
( |
MMA7660_AUTOSLEEP_T |
sr | ) |
|
Sets the sampling rate of the sensor. The value supplied must be one of the MMA7660_AUTOSLEEP_T values.
- Parameters
-
sr | One of the MMA7660_AUTOSLEEP_T values |
- Returns
- True if successful
void installISR |
( |
int |
pin, |
|
|
void(*)(void *) |
isr, |
|
|
void * |
arg |
|
) |
| |
Installs an interrupt service routine (ISR) to be called when an interrupt occurs
- Parameters
-
pin | GPIO pin to use as the interrupt pin |
isr | Pointer to a function to be called on interrupt |
arg | Pointer to an object to be supplied as an argument to the ISR. |
The documentation for this class was generated from the following files: