modified from jppang's MMA8451Q for MMA8491Q on sensor evaluation board with the FRDM-KL25Z

Dependencies:   mbed

Fork of MMA8491Q by JP PANG

Committer:
DiyGuy
Date:
Fri Nov 29 23:14:21 2013 +0000
Revision:
3:3f5c717835c3
Parent:
2:b79d19bdfe10
Added main() example and exercises sensor EN input to trigger new readings

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiyGuy 2:b79d19bdfe10 1 /**
DiyGuy 2:b79d19bdfe10 2 * example MMA8491Q accelerometer on Sensor Evaluation Board
DiyGuy 2:b79d19bdfe10 3 * with the FRDM-KL25Z processor board
DiyGuy 2:b79d19bdfe10 4 */
DiyGuy 2:b79d19bdfe10 5 #include "mbed.h"
DiyGuy 2:b79d19bdfe10 6 #include "MMA8491Q.h"
DiyGuy 2:b79d19bdfe10 7
DiyGuy 2:b79d19bdfe10 8 #define MMA8451_I2C_ADDRESS (0x55<<1)
DiyGuy 2:b79d19bdfe10 9
DiyGuy 2:b79d19bdfe10 10 Serial pc(USBTX, USBRX);
DiyGuy 2:b79d19bdfe10 11
DiyGuy 2:b79d19bdfe10 12 int main(void) {
DiyGuy 2:b79d19bdfe10 13
DiyGuy 2:b79d19bdfe10 14 MMA8491Q acc(PTE0, PTE1, MMA8451_I2C_ADDRESS, PTA13);
DiyGuy 2:b79d19bdfe10 15
DiyGuy 2:b79d19bdfe10 16 PwmOut rled(LED_RED);
DiyGuy 2:b79d19bdfe10 17 PwmOut gled(LED_GREEN);
DiyGuy 2:b79d19bdfe10 18 PwmOut bled(LED_BLUE);
DiyGuy 2:b79d19bdfe10 19
DiyGuy 2:b79d19bdfe10 20 float accX;
DiyGuy 2:b79d19bdfe10 21 float accY;
DiyGuy 2:b79d19bdfe10 22 float accZ;
DiyGuy 2:b79d19bdfe10 23 float accData[3];
DiyGuy 2:b79d19bdfe10 24
DiyGuy 2:b79d19bdfe10 25 while (true) {
DiyGuy 2:b79d19bdfe10 26 /* acc.getAccAllAxis(accData);
DiyGuy 2:b79d19bdfe10 27 accX = accData[0];
DiyGuy 2:b79d19bdfe10 28 accY = accData[1];
DiyGuy 2:b79d19bdfe10 29 accZ = accData[2];
DiyGuy 2:b79d19bdfe10 30 */
DiyGuy 2:b79d19bdfe10 31 accX = acc.getAccX();
DiyGuy 2:b79d19bdfe10 32 accY = acc.getAccY();
DiyGuy 2:b79d19bdfe10 33 accZ = acc.getAccZ();
DiyGuy 2:b79d19bdfe10 34
DiyGuy 2:b79d19bdfe10 35 /* rled = 1.0 - abs(accX);
DiyGuy 2:b79d19bdfe10 36 gled = 1.0 - abs(accX);
DiyGuy 2:b79d19bdfe10 37 bled = 1.0 - abs(accX);
DiyGuy 2:b79d19bdfe10 38 */
DiyGuy 2:b79d19bdfe10 39 pc.printf("X = %5.3f", accX);
DiyGuy 2:b79d19bdfe10 40 pc.printf(" Y = %5.3f", accY);
DiyGuy 2:b79d19bdfe10 41 pc.printf(" Z = %5.3f\r\n", accZ);
DiyGuy 2:b79d19bdfe10 42
DiyGuy 2:b79d19bdfe10 43 wait(1.0);
DiyGuy 2:b79d19bdfe10 44 }
DiyGuy 2:b79d19bdfe10 45 }