Modified for getting access to count data

Dependents:   LCD_punch_mtr_8_v5_class LCD_punch_mtr_8_v5_class LCD_punch_mtr_8_v5_class-Rahul-HW3_2 LCD_punch_mtr_8_v5_DE_32HW ... more

Fork of MMA8451Q8_1 by Stanley Cohen

Committer:
scohennm
Date:
Fri Feb 10 19:07:43 2017 +0000
Revision:
8:6a75e7aec482
Parent:
MMA8451Q8.h@7:ed7e11d269f8
Update of punch program using the accelerometer on the KL46Z

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 1:d2630136d51e 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
samux 1:d2630136d51e 2 *
samux 1:d2630136d51e 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 1:d2630136d51e 4 * and associated documentation files (the "Software"), to deal in the Software without
samux 1:d2630136d51e 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
samux 1:d2630136d51e 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
samux 1:d2630136d51e 7 * Software is furnished to do so, subject to the following conditions:
samux 1:d2630136d51e 8 *
samux 1:d2630136d51e 9 * The above copyright notice and this permission notice shall be included in all copies or
samux 1:d2630136d51e 10 * substantial portions of the Software.
samux 1:d2630136d51e 11 *
samux 1:d2630136d51e 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 1:d2630136d51e 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 1:d2630136d51e 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 1:d2630136d51e 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 1:d2630136d51e 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 1:d2630136d51e 17 */
scohennm 8:6a75e7aec482 18 /*
scohennm 8:6a75e7aec482 19 * Update getGLimit to map to application note AN4076
scohennm 8:6a75e7aec482 20 * http://cache.freescale.com/files/sensors/doc/app_note/AN4076.pdf
scohennm 8:6a75e7aec482 21 * 02/05/2016 sc
scohennm 8:6a75e7aec482 22 */
samux 1:d2630136d51e 23
emilmont 0:6149091f755d 24 #ifndef MMA8451Q_H
emilmont 0:6149091f755d 25 #define MMA8451Q_H
emilmont 0:6149091f755d 26
emilmont 0:6149091f755d 27 #include "mbed.h"
emilmont 0:6149091f755d 28
samux 1:d2630136d51e 29 /**
samux 1:d2630136d51e 30 * MMA8451Q accelerometer example
samux 2:a077541cbadc 31 *
samux 2:a077541cbadc 32 * @code
samux 1:d2630136d51e 33 * #include "mbed.h"
samux 1:d2630136d51e 34 * #include "MMA8451Q.h"
chris 3:db7126dbd63f 35 *
samux 1:d2630136d51e 36 * #define MMA8451_I2C_ADDRESS (0x1d<<1)
chris 3:db7126dbd63f 37 *
chris 4:c4d879a39775 38 * int main(void) {
chris 4:c4d879a39775 39 *
chris 3:db7126dbd63f 40 * MMA8451Q acc(P_E25, P_E24, MMA8451_I2C_ADDRESS);
chris 3:db7126dbd63f 41 * PwmOut rled(LED_RED);
chris 3:db7126dbd63f 42 * PwmOut gled(LED_GREEN);
chris 3:db7126dbd63f 43 * PwmOut bled(LED_BLUE);
chris 3:db7126dbd63f 44 *
chris 3:db7126dbd63f 45 * while (true) {
chris 3:db7126dbd63f 46 * rled = 1.0 - abs(acc.getAccX());
chris 3:db7126dbd63f 47 * gled = 1.0 - abs(acc.getAccY());
chris 3:db7126dbd63f 48 * bled = 1.0 - abs(acc.getAccZ());
chris 3:db7126dbd63f 49 * wait(0.1);
chris 3:db7126dbd63f 50 * }
samux 1:d2630136d51e 51 * }
samux 2:a077541cbadc 52 * @endcode
samux 1:d2630136d51e 53 */
emilmont 0:6149091f755d 54 class MMA8451Q
emilmont 0:6149091f755d 55 {
emilmont 0:6149091f755d 56 public:
samux 1:d2630136d51e 57 /**
samux 1:d2630136d51e 58 * MMA8451Q constructor
samux 1:d2630136d51e 59 *
samux 1:d2630136d51e 60 * @param sda SDA pin
samux 1:d2630136d51e 61 * @param sdl SCL pin
samux 1:d2630136d51e 62 * @param addr addr of the I2C peripheral
emilmont 0:6149091f755d 63 */
emilmont 0:6149091f755d 64 MMA8451Q(PinName sda, PinName scl, int addr);
emilmont 0:6149091f755d 65
samux 1:d2630136d51e 66 /**
samux 1:d2630136d51e 67 * MMA8451Q destructor
emilmont 0:6149091f755d 68 */
emilmont 0:6149091f755d 69 ~MMA8451Q();
emilmont 0:6149091f755d 70
samux 1:d2630136d51e 71 /**
emilmont 0:6149091f755d 72 * Get the value of the WHO_AM_I register
emilmont 0:6149091f755d 73 *
samux 1:d2630136d51e 74 * @returns WHO_AM_I value
emilmont 0:6149091f755d 75 */
emilmont 0:6149091f755d 76 uint8_t getWhoAmI();
emilmont 0:6149091f755d 77
samux 1:d2630136d51e 78 /**
emilmont 0:6149091f755d 79 * Get X axis acceleration
emilmont 0:6149091f755d 80 *
samux 1:d2630136d51e 81 * @returns X axis acceleration
emilmont 0:6149091f755d 82 */
chris 3:db7126dbd63f 83 float getAccX();
scohennm 7:ed7e11d269f8 84
scohennm 7:ed7e11d269f8 85 uint16_t igetAccX();
emilmont 0:6149091f755d 86
samux 1:d2630136d51e 87 /**
emilmont 0:6149091f755d 88 * Get Y axis acceleration
emilmont 0:6149091f755d 89 *
samux 1:d2630136d51e 90 * @returns Y axis acceleration
emilmont 0:6149091f755d 91 */
chris 3:db7126dbd63f 92 float getAccY();
emilmont 0:6149091f755d 93
samux 1:d2630136d51e 94 /**
emilmont 0:6149091f755d 95 * Get Z axis acceleration
emilmont 0:6149091f755d 96 *
samux 1:d2630136d51e 97 * @returns Z axis acceleration
emilmont 0:6149091f755d 98 */
chris 3:db7126dbd63f 99 float getAccZ();
emilmont 0:6149091f755d 100
samux 1:d2630136d51e 101 /**
emilmont 0:6149091f755d 102 * Get XYZ axis acceleration
emilmont 0:6149091f755d 103 *
samux 1:d2630136d51e 104 * @param res array where acceleration data will be stored
emilmont 0:6149091f755d 105 */
chris 3:db7126dbd63f 106 void getAccAllAxis(float * res);
emilmont 0:6149091f755d 107
scohennm 6:e0dc3cd59991 108 int16_t getAccAxis(uint8_t addr);
scohennm 6:e0dc3cd59991 109
samux 1:d2630136d51e 110 I2C m_i2c;
emilmont 0:6149091f755d 111 int m_addr;
scohennm 5:5a7293378401 112 int gChosen;
scohennm 5:5a7293378401 113
scohennm 5:5a7293378401 114 /**
scohennm 5:5a7293378401 115 Allow user to set max g's
scohennm 5:5a7293378401 116 **/
scohennm 5:5a7293378401 117 void setGLimit(int gSelect);
scohennm 8:6a75e7aec482 118 void setStandbyMode();
scohennm 8:6a75e7aec482 119 void setActiveMode();
samux 1:d2630136d51e 120 void readRegs(int addr, uint8_t * data, int len);
samux 1:d2630136d51e 121 void writeRegs(uint8_t * data, int len);
scohennm 5:5a7293378401 122
scohennm 5:5a7293378401 123 private:
scohennm 6:e0dc3cd59991 124
scohennm 5:5a7293378401 125
emilmont 0:6149091f755d 126 };
emilmont 0:6149091f755d 127
emilmont 0:6149091f755d 128 #endif