Library for MMA7660FC Accelerometer device
Dependents: TestCode_MMA7660FC 3D_Accelerometer_Tester RTOS-aap-board-modules embed_Grove_3-Axis_Digital_Accelerometer ... more
Revision 3:df25c72e16be, committed 2012-07-03
- Comitter:
- edodm85
- Date:
- Tue Jul 03 18:37:19 2012 +0000
- Parent:
- 2:88fd58f262c6
- Child:
- 4:6e931d9bbf4b
- Commit message:
- Rev 4
Changed in this revision
MMA7660FC.cpp | Show annotated file Show diff for this revision Revisions of this file |
MMA7660FC.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MMA7660FC.cpp Sun Jul 01 09:50:18 2012 +0000 +++ b/MMA7660FC.cpp Tue Jul 03 18:37:19 2012 +0000 @@ -76,6 +76,57 @@ } + // Reads x data +float MMA7660FC::read_x() +{ + + m_i2c.start(); // Start + m_i2c.write(0x98); // A write to device 0x98 + m_i2c.write(OUT_X); // Register to read + m_i2c.start(); + m_i2c.write(0x99); // Read from device 0x99 + char x = m_i2c.read(0); // Read the data + m_i2c.stop(); + + return (float)x; + +} + + + // Reads y data +float MMA7660FC::read_y() +{ + + m_i2c.start(); // Start + m_i2c.write(0x98); // A write to device 0x98 + m_i2c.write(OUT_Y); // Register to read + m_i2c.start(); + m_i2c.write(0x99); // Read from device 0x99 + char y = m_i2c.read(0); // Read the data + m_i2c.stop(); + + return (float)y; + +} + + + // Reads z data +float MMA7660FC::read_z() +{ + + m_i2c.start(); // Start + m_i2c.write(0x98); // A write to device 0x98 + m_i2c.write(OUT_Z); // Register to read + m_i2c.start(); + m_i2c.write(0x99); // Read from device 0x99 + char z = m_i2c.read(0); // Read the data + m_i2c.stop(); + + return (float)z; + +} + + // Read from specified MMA7660FC register char MMA7660FC::read_reg(char addr) { @@ -83,10 +134,10 @@ m_i2c.start(); // Start m_i2c.write(0x98); // A write to device 0x98 m_i2c.write(addr); // Register to read - m_i2c.start(); // Need to send start condition here + m_i2c.start(); m_i2c.write(0x99); // Read from device 0x99 char c = m_i2c.read(0); // Read the data - m_i2c.stop(); // Stop + m_i2c.stop(); return c;
--- a/MMA7660FC.h Sun Jul 01 09:50:18 2012 +0000 +++ b/MMA7660FC.h Tue Jul 03 18:37:19 2012 +0000 @@ -81,6 +81,24 @@ * @param *z Value of Z acceleration */ void read_g(int *x, int *y, int *z); + + /** Read the x register of the MMA7660FC + * + * @returns The value of x acceleration + */ + float read_x(); + + /** Read the y register of the MMA7660FC + * + * @returns The value of y acceleration + */ + float read_y(); + + /** Read the z register of the MMA7660FC + * + * @returns The value of z acceleration + */ + float read_z(); /** Read from specified MMA7660FC register *