Update of punch program using the accelerometer on the KL46Z
Dependencies: MMA8451Q8a SLCD mbed
Fork of LCD_punch_mtr_8_v5_class by
Revision 1:6c2ec7b0e1c9, committed 2014-11-30
- Comitter:
- scohennm
- Date:
- Sun Nov 30 01:04:47 2014 +0000
- Parent:
- 0:88ddbd76b455
- Child:
- 2:8cdbe8a96b59
- Commit message:
- Changed timer no wait()
Changed in this revision
lcd_acc_46_v3.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/lcd_acc_46_v3.cpp Sun Nov 30 00:08:36 2014 +0000 +++ b/lcd_acc_46_v3.cpp Sun Nov 30 01:04:47 2014 +0000 @@ -9,8 +9,9 @@ Show x and y components */ -#define BLINKTIME 0.5 +#define BLINKTIME 0.7 #define DATATIME 0.1 +#define DATADISPDWELL 0.2 #define NUMLEDS 2 #define LEDON 0 #define LEDOFF 1 @@ -94,12 +95,12 @@ float xOffset; float yOffset; int displayState = true; - float xAcc; - float yAcc; - float zAcc; + float xAcc = 0.0; + float yAcc = 0.0; +// float zAcc; float vector; float vMax = 0.0; - int DisplayTime = DATATIME; + float DisplayTime = DATADISPDWELL; int outState = false; char lcdData[10]; //buffer needs places dor decimal pt and colon @@ -113,6 +114,10 @@ // runLEDs(NUMLEDS); blinkTimer.start(); blinkTimer.reset(); + displayTimer.start(); + displayTimer.reset(); + dataTimer.start(); + dataTimer.reset(); // main loop forever while(true) { @@ -143,32 +148,37 @@ LCDMess(MAXVECT,BLINKTIME); } } - //while (dataTimer.read() > DATATIME){ + +// -------------------------------------------- + while (dataTimer.read() > DATATIME){ //Get accelerometer data - tilt angles minus offset for zero mark. // No offset xAcc = abs(acc.getAccX()); yAcc = abs(acc.getAccY()); - zAcc = abs(acc.getAccZ()); +// zAcc = abs(acc.getAccZ()); // Calulate vector sum of x,y and z reading. - vector = sqrt(pow(xAcc,2) + pow(yAcc,2)+ pow(zAcc,2)); + vector = sqrt(pow(xAcc,2) + pow(yAcc,2)); if (vector > vMax) { vMax = vector; } - wait(DATATIME); + dataTimer.reset(); + } #ifdef PRINTDBUG pc.printf("vector = %f\r\n", yAcc); pc.printf("scaling = %f\r\n", scaleExpansion); pc.printf("RawTemp = %f\r\n", FDeg); #endif // Display the appropriate data on the LCD based upon what mode was chosen - + while (displayTimer.read() > DisplayTime){ if (displayState) { sprintf (lcdData,"%4.3f",yAcc); }else { sprintf (lcdData,"%4.3f",vMax); } - DisplayTime = BLINKTIME; - LCDMess(lcdData,DisplayTime); + // LCDMess(lcdData,DisplayTime); + LCDMessNoDwell(lcdData); + displayTimer.reset(); + } // displaytimer // Wait then do the whole thing again. }//forever loop }// main \ No newline at end of file