GROVE - 3軸加速度センサ サンプルプログラム

Dependencies:   MMA7660FC mbed

Fork of TestCode_MMA7660FC by Edoardo De Marchi

Committer:
edodm85
Date:
Sat Jun 30 10:12:08 2012 +0000
Revision:
0:a006e8002089
Child:
1:78138640bd0e
Rev 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:a006e8002089 1 /* Author: Edoardo De Marchi
edodm85 0:a006e8002089 2 * Name: Test Code for MMA7660FC
edodm85 0:a006e8002089 3 */
edodm85 0:a006e8002089 4 #include "mbed.h"
edodm85 0:a006e8002089 5 #include "MMA7660FC.h"
edodm85 0:a006e8002089 6
edodm85 0:a006e8002089 7 #define ADDR_MMA7660 0x98 // I2C SLAVE ADDR MMA7660FC
edodm85 0:a006e8002089 8
edodm85 0:a006e8002089 9 MMA7660FC Acc(p28, p27, ADDR_MMA7660); //sda, scl, Addr
edodm85 0:a006e8002089 10 Serial pc(USBTX, USBRX);
edodm85 0:a006e8002089 11
edodm85 0:a006e8002089 12
edodm85 0:a006e8002089 13 float G_VALUE[64] = {0, 0.047, 0.094, 0.141, 0.188, 0.234, 0.281, 0.328, 0.375, 0.422, 0.469, 0.516, 0.563, 0.609, 0.656, 0.703, 0.750, 0.797, 0.844, 0.891, 0.938, 0.984, 1.031, 1.078, 1.125, 1.172, 1.219, 1.266, 1.313, 1.359, 1.406, 1.453, -1.500, -1.453, -1.406, -1.359, -1.313, -1.266, -1.219, -1.172, -1.125, -1.078, -1.031, -0.984, -0.938, -0.891, -0.844, -0.797, -0.750, -0.703, -0.656, -0.609, -0.563, -0.516, -0.469, -0.422, -0.375, -0.328, -0.281, -0.234, -0.188, -0.141, -0.094, -0.047};
edodm85 0:a006e8002089 14 float TILT_XY[64] = {0, 2.69, 5.38, 8.08, 10.81, 13.55, 16.33, 19.16, 22.02, 24.95, 27.95, 31.04, 34.23, 37.54, 41.01, 44.68, 48.59, 52.83, 57.54, 62.95, 69.64, 79.86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -79.86, -69.64, -62.95, -57.54, -52.83, -48.59, -44.68, -41.01, -37.54, -34.23, -31.04, -27.95, -24.95, -22.02, -19.16, -16.33, -13.55, -10.81, -8.08, -5.38, -2.69};
edodm85 0:a006e8002089 15 float TILT_Z[64] = {90.00, 87.31, 84.62, 81.92, 79.19, 76.45, 73.67, 70.84, 67.98, 65.05, 62.05, 58.96, 55.77, 52.46, 48.99, 45.32, 41.41, 37.17, 32.46, 27.05, 20.36, 10.14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -10.14, -20.36, -27.05, -32.46, -37.17, -41.41, -45.32, -48.99, -52.46, -55.77, -58.96, -62.05, -65.05, -67.98, -70.84, -73.67, -76.45, -79.19, -81.92, -84.62};
edodm85 0:a006e8002089 16
edodm85 0:a006e8002089 17
edodm85 0:a006e8002089 18
edodm85 0:a006e8002089 19 int main()
edodm85 0:a006e8002089 20 {
edodm85 0:a006e8002089 21
edodm85 0:a006e8002089 22 Acc.init(); // Initialization
edodm85 0:a006e8002089 23 pc.printf("Value reg 0x06: %#x\n", Acc.read_reg(0x06)); // Test the correct value of the register 0x06
edodm85 0:a006e8002089 24 pc.printf("Value reg 0x08: %#x\n", Acc.read_reg(0x08)); // Test the correct value of the register 0x08
edodm85 0:a006e8002089 25 pc.printf("Value reg 0x07: %#x\n\r", Acc.read_reg(0x07)); // Test the correct value of the register 0x07
edodm85 0:a006e8002089 26
edodm85 0:a006e8002089 27 while(1)
edodm85 0:a006e8002089 28 {
edodm85 0:a006e8002089 29 int x=0, y=0, z=0;
edodm85 0:a006e8002089 30
edodm85 0:a006e8002089 31 Acc.read_g(&x, &y, &z); // Read the acceleration
edodm85 0:a006e8002089 32
edodm85 0:a006e8002089 33 pc.printf("x: %1.3fg \n", G_VALUE[x]); // Print the X axis acceleration in g
edodm85 0:a006e8002089 34 pc.printf("y: %1.3fg \n", G_VALUE[y]); // Print the Y axis acceleration in g
edodm85 0:a006e8002089 35 pc.printf("z: %1.3fg \n", G_VALUE[z]); // Print the Z axis acceleration in g
edodm85 0:a006e8002089 36
edodm85 0:a006e8002089 37
edodm85 0:a006e8002089 38 pc.printf("Tilt x: %2.2f degree \n", TILT_XY[x]); // Print the tilt orientation of the X axis
edodm85 0:a006e8002089 39 pc.printf("Tilt y: %2.2f degree \n", TILT_XY[y]); // Print the tilt orientation of the Y axis
edodm85 0:a006e8002089 40 pc.printf("Tilt z: %2.2f degree \n", TILT_Z[z]); // Print the tilt orientation of the Z axis
edodm85 0:a006e8002089 41
edodm85 0:a006e8002089 42 pc.printf("\n");
edodm85 0:a006e8002089 43 wait(2);
edodm85 0:a006e8002089 44
edodm85 0:a006e8002089 45 }
edodm85 0:a006e8002089 46 }
edodm85 0:a006e8002089 47