KBrat-SSD541-HW-15-1
Dependencies: MMA8451Q KBrat-SSD541-HW-15-1 mbed
Fork of ACC_LCD_341_Basic by
Diff: acc_341.cpp
- Revision:
- 6:4750e5732aca
- Parent:
- 5:29c6ba524263
--- a/acc_341.cpp Mon Nov 14 15:50:33 2016 +0000 +++ b/acc_341.cpp Mon Nov 28 16:40:30 2016 +0000 @@ -2,6 +2,9 @@ #include <math.h> #include "MMA8451Q.h" #include "SLCD.h" +#define NUMBUTS 2 //two buttons +#define LBUT PTC12 //left button // port addresses for buttons +#define RBUT PTC3 //right button /* Test of the accelerometer, digital I/O, on-board LCD screen. @@ -9,13 +12,20 @@ Works pretty well. Still rough, program wise - sc 140710 */ -#define DATAINTERVAL 0.200 +//#define DATAINTERVAL 0.200 +#define DATAINTERVAL 1.0 #define LCDDATALEN 10 - -#define PROGNAME "ACCLCD341-541\r\n" +#define BUTTONTIME 0.2 +#define PROGNAME "KBrat-SSD541-HW-15.1\r\n" #define PRINTDBUG -// + +//----------------------------// + + + +//----------------------------// + #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) PinName const SDA = PTE25; // Data pins for the accelerometer/magnetometer. PinName const SCL = PTE24; // DO NOT CHANGE @@ -32,10 +42,10 @@ char lcdData[LCDDATALEN]; //buffer needs places dor decimal pt and colon MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); -Serial pc(USBTX, USBRX); -Timer dataTimer; +Serial pc(USBTX, USBRX);// set up USB as communicationis to Host PC via USB connectons +Timer ButtonTimer; // for reading button states - +DigitalIn buttons[NUMBUTS] = {RBUT, LBUT}; void LCDMess(char *lMess){ slcd.Home(); @@ -50,34 +60,68 @@ } void initialize_global_vars(){ - pc.printf(PROGNAME); - dataTimer.start(); - dataTimer.reset(); + pc.printf(PROGNAME); + // set up DAQ timers + ButtonTimer.start(); + ButtonTimer.reset(); } + int main() { float xAcc; float yAcc; float zAcc; - initialize_global_vars(); -// main loop forever + //initialize_global_vars(); + + int i; + + initialize_global_vars(); //keep things organized + +// End of setup while(true) { - if(dataTimer.read() > DATAINTERVAL){ - dataTimer.reset(); -//Get accelerometer data - tilt angles minus offset for zero mark. - xAcc = acc.getAccX(); - 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 + if (ButtonTimer > BUTTONTIME){ + for (i=0; i<NUMBUTS; i++){ // index will be 0 or 1 + if(!buttons[i]) { + if (i==1) + xAcc = acc.getAccX(); + yAcc = acc.getAccY(); + zAcc = acc.getAccZ(); - LCDsignedFloat(xAcc); + slcd.printf("X"); + wait(0.3); + slcd.clear(); + pc.printf("xAcc = %f\r\n", xAcc); + LCDsignedFloat(xAcc); + wait(1.5); + + slcd.printf("Y"); + wait(0.3); + slcd.clear(); + pc.printf("yAcc = %f\r\n", yAcc); + LCDsignedFloat(yAcc); + wait(1.5); + + slcd.printf("z"); + wait(0.3); + slcd.clear(); + pc.printf("zAcc = %f\r\n", zAcc); + LCDsignedFloat(zAcc); + // Wait then do the whole thing again. - } + + + } // if ! buttons + }// for loop to look at buttons + ButtonTimer.reset(); + } + } -} \ No newline at end of file + +} + + + + + +