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 3:c5291c70af48, committed 2016-11-05
- Comitter:
- scohennm
- Date:
- Sat Nov 05 23:46:00 2016 +0000
- Parent:
- 2:6003ed409def
- Child:
- 4:1d559bac561a
- Commit message:
- Added negative sign for display and updated data interval.
Changed in this revision
| SLCD.lib | Show annotated file Show diff for this revision Revisions of this file |
| acc_341.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/SLCD.lib Thu Sep 25 23:45:35 2014 +0000 +++ b/SLCD.lib Sat Nov 05 23:46:00 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01 +https://developer.mbed.org/users/scohennm/code/SLCD_minus_mod/#ee727b8319f4
--- a/acc_341.cpp Thu Sep 25 23:45:35 2014 +0000
+++ b/acc_341.cpp Sat Nov 05 23:46:00 2016 +0000
@@ -1,4 +1,5 @@
#include "mbed.h"
+#include <math.h>
#include "MMA8451Q.h"
#include "SLCD.h"
@@ -8,9 +9,9 @@
Works pretty well. Still rough, program wise - sc 140710
*/
-#define DATATIME 0.200
+#define DATAINTERVAL 0.200
-#define PROGNAME "ACCLCD341\r/n"
+#define PROGNAME "ACCLCD341-541\r\n"
#define PRINTDBUG
//
@@ -30,48 +31,44 @@
MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
Serial pc(USBTX, USBRX);
+Timer dataTimer;
-float sqrt_newt(float argument) {
- return (sqrt(argument));
-}
-void LCDMess(char *lMess, float dWait){
+void LCDMess(char *lMess){
slcd.Home();
slcd.clear();
slcd.printf(lMess);
- wait(dWait);
}
-
+void initialize_global_vars(){
+ pc.printf(PROGNAME);
+ dataTimer.start();
+ dataTimer.reset();
+}
int main() {
float xAcc;
- float yAcc;
- float vector;
+ float yAcc;
char lcdData[10]; //buffer needs places dor decimal pt and colon
-#ifdef PRINTDBUG
- pc.printf(PROGNAME);
-#endif
+ initialize_global_vars();
// main loop forever
while(true) {
-
+ if(dataTimer.read() > DATAINTERVAL){
+ dataTimer.reset();
//Get accelerometer data - tilt angles minus offset for zero mark.
- xAcc = abs(acc.getAccX());
- yAcc = abs(acc.getAccY());
- // Calulate vector sum of x and y reading.
- vector = sqrt_newt(pow(xAcc,2) + pow(yAcc,2));
-
+ xAcc = acc.getAccX();
+ yAcc = acc.getAccY();
#ifdef PRINTDBUG
pc.printf("xAcc = %f\r\n", xAcc);
pc.printf("yAcc = %f\r\n", yAcc);
- pc.printf("vector = %f\r\n", vector);
#endif
- sprintf (lcdData,"%4.3f",vector);
- LCDMess(lcdData, DATATIME);
+ sprintf (lcdData,"%3.2f",xAcc);
+ if (xAcc < 0) sprintf (lcdData,">%3.2f",fabs(xAcc));
+ LCDMess(lcdData);
// Wait then do the whole thing again.
- wait(DATATIME);
+ }
}
}
\ No newline at end of file
