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 SLCD_minus_mod mbed
Fork of ACC_LCD_341_Basic by
Revision 4:1d559bac561a, committed 2016-11-06
- Comitter:
- scohennm
- Date:
- Sun Nov 06 23:56:18 2016 +0000
- Parent:
- 3:c5291c70af48
- Child:
- 5:29c6ba524263
- Commit message:
- z-Axis displayed
Changed in this revision
| acc_341.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/acc_341.cpp Sat Nov 05 23:46:00 2016 +0000
+++ b/acc_341.cpp Sun Nov 06 23:56:18 2016 +0000
@@ -10,6 +10,7 @@
*/
#define DATAINTERVAL 0.200
+#define LCDDATALEN 10
#define PROGNAME "ACCLCD341-541\r\n"
@@ -28,6 +29,7 @@
#define MMA8451_I2C_ADDRESS (0x1d<<1)
SLCD slcd; //define LCD display
+char lcdData[LCDDATALEN]; //buffer needs places dor decimal pt and colon
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
Serial pc(USBTX, USBRX);
@@ -40,6 +42,13 @@
slcd.clear();
slcd.printf(lMess);
}
+
+void LCDsignedFloat(float theNumber){
+ sprintf (lcdData,"%3.2f",theNumber);
+ if (theNumber < 0.0) sprintf (lcdData,">%3.2f",fabs(theNumber));
+ LCDMess(lcdData);
+}
+
void initialize_global_vars(){
pc.printf(PROGNAME);
dataTimer.start();
@@ -49,7 +58,7 @@
int main() {
float xAcc;
float yAcc;
- char lcdData[10]; //buffer needs places dor decimal pt and colon
+ float zAcc;
initialize_global_vars();
// main loop forever
@@ -58,16 +67,16 @@
dataTimer.reset();
//Get accelerometer data - tilt angles minus offset for zero mark.
xAcc = acc.getAccX();
- yAcc = acc.getAccY();
+ yAcc = acc.getAccY();
+ zAcc = acc.getAccZ();
#ifdef PRINTDBUG
pc.printf("xAcc = %f\r\n", xAcc);
pc.printf("yAcc = %f\r\n", yAcc);
+ pc.printf("zAcc = %f\r\n", zAcc);
#endif
- sprintf (lcdData,"%3.2f",xAcc);
- if (xAcc < 0) sprintf (lcdData,">%3.2f",fabs(xAcc));
- LCDMess(lcdData);
+ LCDsignedFloat(zAcc);
// Wait then do the whole thing again.
}
}
