HW-15.1
Dependencies: MMA8451Q SLCD_minus_mod mbed
Fork of ACC_LCD_341_Basic by
Diff: acc_341.cpp
- Revision:
- 6:f53933d232fc
- Parent:
- 5:29c6ba524263
diff -r 29c6ba524263 -r f53933d232fc acc_341.cpp --- a/acc_341.cpp Mon Nov 14 15:50:33 2016 +0000 +++ b/acc_341.cpp Mon Nov 28 04:56:16 2016 +0000 @@ -12,6 +12,19 @@ #define DATAINTERVAL 0.200 #define LCDDATALEN 10 +#define LEDON false +#define LEDOFF true +#define BUTDOWN false +#define BUTUP true +#define NUMBUTS 2 +#define LBUT PTC12 +#define RBUT PTC3 +#define LRED "Y " +#define LGREEN "X " +#define PRED "Y\r\n" +#define PGREEN "X\r\n" +#define NUMMESS 2 + #define PROGNAME "ACCLCD341-541\r\n" #define PRINTDBUG @@ -31,6 +44,11 @@ SLCD slcd; //define LCD display char lcdData[LCDDATALEN]; //buffer needs places dor decimal pt and colon +int ledState = LEDON; +int buttonStates[NUMBUTS] = {BUTDOWN,BUTUP}; +DigitalIn buttons[NUMBUTS] = {RBUT, LBUT}; +DigitalOut LEDs[NUMBUTS] = {LED_GREEN, LED_RED}; + MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); Serial pc(USBTX, USBRX); Timer dataTimer; @@ -59,7 +77,12 @@ float xAcc; float yAcc; float zAcc; - + //-------------- + int i; + int currentLED = 0; + char rMess[NUMMESS][LCDDATALEN]={LGREEN, LRED}; + char pMess[NUMMESS][LCDDATALEN]={xAcc, yAcc}; + initialize_global_vars(); // main loop forever while(true) { @@ -70,13 +93,47 @@ yAcc = acc.getAccY(); zAcc = acc.getAccZ(); + + + while(true) { + for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1 + LEDs[i] = LEDOFF; + // if(buttons[i] == BUTDOWN) { + if(!buttons[0]) { + LCDMess(rMess[0]); + wait(0.5); + //LCDMess(pMess[i]); + xAcc = acc.getAccX(); + LCDsignedFloat(xAcc); + currentLED = 0; + } + if(!buttons[1]) { + LCDMess(rMess[1]); + wait(0.5); + yAcc = acc.getAccY(); + LCDsignedFloat(yAcc); + currentLED = 1; + } + } + + ledState = !ledState; // Flip the general state + LEDs[currentLED] = ledState; + wait(0.01); + + + } + + + + #ifdef PRINTDBUG pc.printf("xAcc = %f\r\n", xAcc); pc.printf("yAcc = %f\r\n", yAcc); pc.printf("zAcc = %f\r\n", zAcc); #endif + - LCDsignedFloat(xAcc); + // Wait then do the whole thing again. } }