Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MMA8451Q TextLCD mbed
main.cpp
00001 #include "mbed.h" 00002 #include "MMA8451Q.h" 00003 #include "TextLCD.h" 00004 #define MMA8451_I2C_ADDRESS (0x1d<<1) 00005 00006 TextLCD lcd(D2, D3, D4, D5, D6, D7); // LCD PIN => RS, EN, Data4, Data5, Data6, Data7 00007 00008 PinName const SDA = PTE25; //I2C Pins for KL25Z 00009 PinName const SCL = PTE24; //I2C Pins for KL25Z 00010 00011 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); //Initilize MMA8451Q Accelerometer 00012 00013 int main(void) 00014 { 00015 lcd.cls(); // Clear LCD 00016 lcd.locate(0,0); // cursor on Col=0, Raw=0 00017 lcd.printf("Experiment - 8"); // print startup message on LCD first Raw 00018 lcd.locate(0,1); // cursor on Col=0, Raw=1 00019 lcd.printf("MMA8451 With LCD"); // print startup message on LCD second Raw 00020 wait(3.0); // wait 3 second to show startup message 00021 while (1) 00022 { 00023 float x, y, z; 00024 x = acc.getAccX(); // get Acceleration on X 00025 y = acc.getAccY(); // get Acceleration on Y 00026 z = acc.getAccZ(); // get Acceleration on Z 00027 lcd.cls(); // Clear LCD 00028 lcd.locate(0,0); // cursor on Col=0, Raw=0 00029 lcd.printf("X:%0.2f",x); // print value of X in first line of LCD 00030 lcd.locate(8,0); // cursor on Col=8, Raw=0 00031 lcd.printf("Y:%0.2f",y); // print value of Y in first line of LCD 00032 lcd.locate(4,1); // cursor on Col=5, Raw=1 00033 lcd.printf("Z:%0.2f",z); // print value of Z in first line of LCD 00034 wait(0.1); // Wait for 100ms to visulize reading on LCD 00035 00036 } 00037 }
Generated on Mon Aug 1 2022 02:16:25 by
1.7.2