Sbart-SSD341-HW-15.1
Dependencies: MMA8451Q SLCD_minus_mod mbed
Fork of ACC_LCD_341_Basic by
Revision 6:7dd868f0d3b8, committed 2016-11-28
- Comitter:
- sbart
- Date:
- Mon Nov 28 00:21:41 2016 +0000
- Parent:
- 5:29c6ba524263
- Commit message:
- SBart-SSD341-HW-15.1
Changed in this revision
acc_341.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 29c6ba524263 -r 7dd868f0d3b8 acc_341.cpp --- a/acc_341.cpp Mon Nov 14 15:50:33 2016 +0000 +++ b/acc_341.cpp Mon Nov 28 00:21:41 2016 +0000 @@ -12,7 +12,15 @@ #define DATAINTERVAL 0.200 #define LCDDATALEN 10 +#define LCDWAIT 1.5 + +#define NUMBUTS 1 +#define LBUT PTC12 // port addresses for buttons +//#define RBUT PTC3 +#define BUTTONTIME 0.1 + #define PROGNAME "ACCLCD341-541\r\n" +#define LCDTIME 1.5 #define PRINTDBUG // @@ -35,7 +43,15 @@ Serial pc(USBTX, USBRX); Timer dataTimer; - +Timer ButtonTimer; // for reading button states +Timer LCDTimer; + +DigitalIn buttons[NUMBUTS] = {LBUT}; + +char axisName[3] = {'X', 'Y', 'Z'}; + +int currentAxis; +int displayState; void LCDMess(char *lMess){ slcd.Home(); @@ -46,13 +62,22 @@ void LCDsignedFloat(float theNumber){ sprintf (lcdData," %3.2f",theNumber); if (theNumber < 0.0) sprintf (lcdData,"<%3.2f",fabs(theNumber)); - LCDMess(lcdData); + LCDMess(lcdData); } void initialize_global_vars(){ pc.printf(PROGNAME); dataTimer.start(); - dataTimer.reset(); + dataTimer.reset(); + + ButtonTimer.start(); + ButtonTimer.reset(); + + currentAxis = 0; + displayState = 0; + +// LCDTimer.start(); +// LCDTimer.reset(); } int main() { @@ -76,8 +101,68 @@ pc.printf("zAcc = %f\r\n", zAcc); #endif - LCDsignedFloat(xAcc); +while (true) { + if (ButtonTimer > BUTTONTIME){ + //float count = 0; + for (int i=0; i<NUMBUTS; i++){ // index will be 0 or 1 + if(!buttons[0]) { + pc.printf("Left Button Clicked"); + //char ch_ds = displayState; + //pc.printf("displayState = " + ch_ds); + displayState++; + if(displayState > 3) + displayState = 1; + // do something here. + switch (displayState) { + case 1: + pc.printf("Case1"); +// currentAxis = xAcc; + currentAxis = displayState - 1; +// LCDMess((char*)axisName[currentAxis]); + slcd.clear(); + slcd.putc('X'); + wait(LCDWAIT); + xAcc = acc.getAccX(); + LCDsignedFloat(xAcc); + break; + case 2: + pc.printf("Case2"); +// currentAxis = yAcc; + currentAxis = displayState - 1; +// LCDMess((char*)axisName[currentAxis]); + slcd.clear(); + slcd.putc('Y'); + wait(LCDWAIT); + yAcc = acc.getAccY(); + LCDsignedFloat(yAcc); + break; + case 3: + pc.printf("Case3"); +// currentAxis = zAcc; + currentAxis = displayState - 1; +// LCDMess((char*)axisName[currentAxis]); + slcd.clear(); + slcd.putc('Z'); + wait(LCDWAIT); + zAcc = acc.getAccZ(); + LCDsignedFloat(zAcc); + break; + default: +// currentAxis = xAcc; + xAcc = acc.getAccX(); + LCDsignedFloat(xAcc); + break; + } + } // if ! buttons + }// for loop to look at buttons + ButtonTimer.reset(); + } + + + } +} + // Wait then do the whole thing again. - } +// } } } \ No newline at end of file