EXP7

Dependencies:   MMA8451Q mbed

Committer:
rx5
Date:
Wed Apr 13 05:39:00 2016 +0000
Revision:
0:df0f45be8441
EXP7

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rx5 0:df0f45be8441 1 #include "mbed.h"
rx5 0:df0f45be8441 2 #include "MMA8451Q.h"
rx5 0:df0f45be8441 3 #define MMA8451_I2C_ADDRESS (0x1d<<1)
rx5 0:df0f45be8441 4
rx5 0:df0f45be8441 5 Serial pc(USBTX, USBRX); // Initlize UART on USB port of KL25Z with default Baud 9600
rx5 0:df0f45be8441 6
rx5 0:df0f45be8441 7 PinName const SDA = PTE25; //I2C Pins for KL25Z
rx5 0:df0f45be8441 8 PinName const SCL = PTE24; //I2C Pins for KL25Z
rx5 0:df0f45be8441 9
rx5 0:df0f45be8441 10 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); //Initilize MMA8451Q Accelerometer
rx5 0:df0f45be8441 11
rx5 0:df0f45be8441 12 int main(void)
rx5 0:df0f45be8441 13 {
rx5 0:df0f45be8441 14 // pc.baud(115200); // uncomment this line and update baudrate to cahnge baud rate from 9600 default
rx5 0:df0f45be8441 15
rx5 0:df0f45be8441 16 pc.printf("\r\n"); // print startup message from new line on UART Terminal
rx5 0:df0f45be8441 17 pc.printf("Experiment - 7\r\n"); // print startup message on UART Terminal
rx5 0:df0f45be8441 18 pc.printf("MMA8451 Interfacing With UART"); // print startup message from new line on UART Terminal
rx5 0:df0f45be8441 19 pc.printf("\r\n"); // print startup message from new line on UART Terminal
rx5 0:df0f45be8441 20 wait(2.0);
rx5 0:df0f45be8441 21 while (1) {
rx5 0:df0f45be8441 22 float x, y, z;
rx5 0:df0f45be8441 23 x = acc.getAccX(); // get Acceleration on X
rx5 0:df0f45be8441 24 y = acc.getAccY(); // get Acceleration on Y
rx5 0:df0f45be8441 25 z = acc.getAccZ(); // get Acceleration on Z
rx5 0:df0f45be8441 26 wait(0.1);
rx5 0:df0f45be8441 27 pc.printf("X: %0.2f, \tY: %0.2f, \tZ: %0.2f\n", x, y, z); //Print X,Y,Z Acceleration on UART Terminal
rx5 0:df0f45be8441 28 }
rx5 0:df0f45be8441 29 }