programa para ver la posición de la tarjeta por medio del acelerometro que trae incorporado

Dependencies:   TextLCD3libreriatexlcd mbed

Fork of MMA8451Q by Johan Kritzinger

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.
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.
void setDoubleTap (void)
 JK Setup Double Tap detection.

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 42 of file MMA8451Q.cpp.

~MMA8451Q (  )

MMA8451Q destructor.

Definition at line 48 of file MMA8451Q.cpp.


Member Function Documentation

void getAccAllAxis ( float *  res )

Get XYZ axis acceleration.

Parameters:
resarray where acceleration data will be stored

Definition at line 69 of file MMA8451Q.cpp.

float getAccX (  )

Get X axis acceleration.

Returns:
X axis acceleration

Definition at line 56 of file MMA8451Q.cpp.

float getAccY (  )

Get Y axis acceleration.

Returns:
Y axis acceleration

Definition at line 61 of file MMA8451Q.cpp.

float getAccZ (  )

Get Z axis acceleration.

Returns:
Z axis acceleration

Definition at line 65 of file MMA8451Q.cpp.

uint8_t getWhoAmI (  )

Get the value of the WHO_AM_I register.

Returns:
WHO_AM_I value

Definition at line 50 of file MMA8451Q.cpp.

void setDoubleTap ( void   )

JK Setup Double Tap detection.

Example:

include "mbed.h" include "MMA8451Q.h"

define MMA8451_I2C_ADDRESS (0x1d<<1) define ON 0 define OFF !ON

Setup the interrupts for the MMA8451Q InterruptIn accInt1(PTA14); InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer

uint8_t togstat=0;//Led status DigitalOut bled(LED_BLUE);

void tapTrue(void){//ISR if(togstat == 0){ togstat = 1; bled=ON; } else { togstat = 0; bled=OFF; }

}

int main(void) {

MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);//accelorometer instance

acc.setDoubleTap();//Setup the MMA8451Q to look for a double Tap accInt1.rise(&tapTrue);//call tapTrue when an interrupt is generated on PTA14

while (true) { Interrupt driven so nothing in main loop } }

Definition at line 87 of file MMA8451Q.cpp.