EXP8

Dependencies:   MMA8451Q TextLCD mbed

Committer:
rx5
Date:
Wed Apr 13 05:39:58 2016 +0000
Revision:
0:8273605d433b
EXP8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rx5 0:8273605d433b 1 #include "mbed.h"
rx5 0:8273605d433b 2 #include "MMA8451Q.h"
rx5 0:8273605d433b 3 #include "TextLCD.h"
rx5 0:8273605d433b 4 #define MMA8451_I2C_ADDRESS (0x1d<<1)
rx5 0:8273605d433b 5
rx5 0:8273605d433b 6 TextLCD lcd(D2, D3, D4, D5, D6, D7); // LCD PIN => RS, EN, Data4, Data5, Data6, Data7
rx5 0:8273605d433b 7
rx5 0:8273605d433b 8 PinName const SDA = PTE25; //I2C Pins for KL25Z
rx5 0:8273605d433b 9 PinName const SCL = PTE24; //I2C Pins for KL25Z
rx5 0:8273605d433b 10
rx5 0:8273605d433b 11 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); //Initilize MMA8451Q Accelerometer
rx5 0:8273605d433b 12
rx5 0:8273605d433b 13 int main(void)
rx5 0:8273605d433b 14 {
rx5 0:8273605d433b 15 lcd.cls(); // Clear LCD
rx5 0:8273605d433b 16 lcd.locate(0,0); // cursor on Col=0, Raw=0
rx5 0:8273605d433b 17 lcd.printf("Experiment - 8"); // print startup message on LCD first Raw
rx5 0:8273605d433b 18 lcd.locate(0,1); // cursor on Col=0, Raw=1
rx5 0:8273605d433b 19 lcd.printf("MMA8451 With LCD"); // print startup message on LCD second Raw
rx5 0:8273605d433b 20 wait(3.0); // wait 3 second to show startup message
rx5 0:8273605d433b 21 while (1)
rx5 0:8273605d433b 22 {
rx5 0:8273605d433b 23 float x, y, z;
rx5 0:8273605d433b 24 x = acc.getAccX(); // get Acceleration on X
rx5 0:8273605d433b 25 y = acc.getAccY(); // get Acceleration on Y
rx5 0:8273605d433b 26 z = acc.getAccZ(); // get Acceleration on Z
rx5 0:8273605d433b 27 lcd.cls(); // Clear LCD
rx5 0:8273605d433b 28 lcd.locate(0,0); // cursor on Col=0, Raw=0
rx5 0:8273605d433b 29 lcd.printf("X:%0.2f",x); // print value of X in first line of LCD
rx5 0:8273605d433b 30 lcd.locate(8,0); // cursor on Col=8, Raw=0
rx5 0:8273605d433b 31 lcd.printf("Y:%0.2f",y); // print value of Y in first line of LCD
rx5 0:8273605d433b 32 lcd.locate(4,1); // cursor on Col=5, Raw=1
rx5 0:8273605d433b 33 lcd.printf("Z:%0.2f",z); // print value of Z in first line of LCD
rx5 0:8273605d433b 34 wait(0.1); // Wait for 100ms to visulize reading on LCD
rx5 0:8273605d433b 35
rx5 0:8273605d433b 36 }
rx5 0:8273605d433b 37 }