Library for MMA7660FC Accelerometer device
Dependents: TestCode_MMA7660FC 3D_Accelerometer_Tester RTOS-aap-board-modules embed_Grove_3-Axis_Digital_Accelerometer ... more
MMA7660FC.h
- Committer:
- edodm85
- Date:
- 2012-07-05
- Revision:
- 5:d2f90c0be13f
- Parent:
- 4:6e931d9bbf4b
- Child:
- 6:10aa804dee97
File content as of revision 5:d2f90c0be13f:
// Author: Edoardo De Marchi /* Copyright (C) 2012 mbed.org, MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef MBED_MMA7660FC_H #define MBED_MMA7660FC_H #include "mbed.h" /** Accelerometer MMA7660FC class * * Example: * @code * * #include "mbed.h" * #include "MMA7660FC.h" * * #define ADDR_MMA7660 0x98 * * MMA7660FC Acc(p28, p27, ADDR_MMA7660); * serial pc(USBTX, USBRX); * * int main() * { * Acc.init(); * while(1) * { * int x=0, y=0, z=0; * Acc.read_Tilt(&x, &y, &z); * pc.printf("Tilt x: %2.2f degree \n", x); // Print the tilt orientation of the X axis * pc.printf("Tilt y: %2.2f degree \n", y); // Print the tilt orientation of the Y axis * pc.printf("Tilt z: %2.2f degree \n", z); // Print the tilt orientation of the Z axis * wait(1); * } * } * @endcode */ class MMA7660FC { public: /** Create an MMA7660FC object connected to the specified I2C object * * @param sda I2C data port * @param scl I2C clock port * @param addr The address of the MMA7660FC */ MMA7660FC(PinName sda, PinName scl, int addr); /** Destroys an MMA7660FC object * */ ~MMA7660FC(); /** Initialization of device MMA7660FC (required) * */ void init(); /** Read the Tilt Angle using Three Axis * * @param *x Value of x tilt * @param *y Value of y tilt * @param *z Value of z tilt */ void read_Tilt(float *x, float *y, float *z); /** Read the x register of the MMA7660FC * * @returns The value of x acceleration */ int read_x(); /** Read the y register of the MMA7660FC * * @returns The value of y acceleration */ int read_y(); /** Read the z register of the MMA7660FC * * @returns The value of z acceleration */ int read_z(); /** Read from specified MMA7660FC register * * @param addr The internal registeraddress of the MMA7660FC * @returns The value of the register */ char read_reg(char addr); /** Write to specified MMA7660FC register * * @param addr The internal registeraddress of the MMA7660FC * @param data New value of the register */ void write_reg(char addr, char data); private: I2C m_i2c; int m_addr; }; #endif