1 /* Copyright (c) 2010-2011 mbed.org, MIT License
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
4 * and associated documentation files (the "Software"), to deal in the Software without
5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
7 * Software is furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in all copies or
10 * substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * MMA8451Q accelerometer example
29 * #include "MMA8451Q.h"
31 * #define MMA8451_I2C_ADDRESS (0x1d<<1)
35 * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
36 * PwmOut rled(LED_RED);
37 * PwmOut gled(LED_GREEN);
38 * PwmOut bled(LED_BLUE);
41 * rled = 1.0 - abs(acc.getAccX());
42 * gled = 1.0 - abs(acc.getAccY());
43 * bled = 1.0 - abs(acc.getAccZ());
53 * MMA8451Q constructor
57 * @param addr addr of the I2C peripheral
59 MMA8451Q(PinName sda, PinName scl, int addr);
67 * Get the value of the WHO_AM_I register
69 * @returns WHO_AM_I value
74 * Get X axis acceleration
76 * @returns X axis acceleration
81 * Get Y axis acceleration
83 * @returns Y axis acceleration
88 * Get Z axis acceleration
90 * @returns Z axis acceleration
95 * Get XYZ axis acceleration
97 * @param res array where acceleration data will be stored
99 void getAccAllAxis(float * res);
102 * Setup Double Tap detection
108 #include "MMA8451Q.h"
110 #define MMA8451_I2C_ADDRESS (0x1d<<1)
114 //Setup the interrupts for the MMA8451Q
115 InterruptIn accInt1(PTA14);
116 InterruptIn accInt2(PTA15);//not used in this prog but this is the other int from the accelorometer
118 uint8_t togstat=0;//Led status
119 DigitalOut bled(LED_BLUE);
122 void tapTrue(void){//ISR
136 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);//accelorometer instance
138 acc.setDoubleTap();//Setup the MMA8451Q to look for a double Tap
139 accInt1.rise(&tapTrue);//call tapTrue when an interrupt is generated on PTA14
142 //Interrupt driven so nothing in main loop
148 void setDoubleTap(void);
153 void readRegs(int addr, uint8_t * data, int len);
154 void writeRegs(uint8_t * data, int len);
155 int16_t getAccAxis(uint8_t addr);