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.
Fork of MMA8452Q by
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:
-
sda SDA pin sdl SCL pin addr addr 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:
-
res array where acceleration data will be stored
Definition at line 95 of file MMA8452Q.cpp.
| float getAccX | ( | ) |
| float getAccY | ( | ) |
| float getAccZ | ( | ) |
| 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.
Generated on Wed Jul 20 2022 07:09:01 by
1.7.2
