Sbart-SSD341-HW-15.1

Dependencies:   MMA8451Q SLCD_minus_mod mbed

Fork of ACC_LCD_341_Basic by Stanley Cohen

Committer:
scohennm
Date:
Thu Sep 25 16:27:26 2014 +0000
Revision:
1:9340a340e588
Parent:
0:203b4129a213
Child:
2:6003ed409def
Updated pc.printf diagonstics

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scohennm 0:203b4129a213 1 #include "mbed.h"
scohennm 0:203b4129a213 2 #include "MMA8451Q.h"
scohennm 0:203b4129a213 3 #include "SLCD.h"
scohennm 0:203b4129a213 4
scohennm 0:203b4129a213 5 /*
scohennm 0:203b4129a213 6 Test of the accelerometer, digital I/O, on-board LCD screen.
scohennm 0:203b4129a213 7 Looing at vector product of the x-y components of the accelerometer.
scohennm 0:203b4129a213 8 Works pretty well. Still rough, program wise - sc 140710
scohennm 0:203b4129a213 9 */
scohennm 0:203b4129a213 10
scohennm 0:203b4129a213 11 #define DATATIME 0.200
scohennm 0:203b4129a213 12
scohennm 0:203b4129a213 13 #define PROGNAME "ACCLCD341\r/n"
scohennm 0:203b4129a213 14
scohennm 0:203b4129a213 15 #define PRINTDBUG
scohennm 0:203b4129a213 16
scohennm 0:203b4129a213 17 #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
scohennm 0:203b4129a213 18 PinName const SDA = PTE25;
scohennm 0:203b4129a213 19 PinName const SCL = PTE24;
scohennm 0:203b4129a213 20 #elif defined (TARGET_KL05Z)
scohennm 0:203b4129a213 21 PinName const SDA = PTB4;
scohennm 0:203b4129a213 22 PinName const SCL = PTB3;
scohennm 0:203b4129a213 23 #else
scohennm 0:203b4129a213 24 #error TARGET NOT DEFINED
scohennm 0:203b4129a213 25 #endif
scohennm 0:203b4129a213 26
scohennm 0:203b4129a213 27 #define MMA8451_I2C_ADDRESS (0x1d<<1)
scohennm 0:203b4129a213 28
scohennm 0:203b4129a213 29 SLCD slcd; //define LCD display
scohennm 0:203b4129a213 30
scohennm 0:203b4129a213 31 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
scohennm 0:203b4129a213 32 Serial pc(USBTX, USBRX);
scohennm 0:203b4129a213 33
scohennm 0:203b4129a213 34
scohennm 0:203b4129a213 35
scohennm 0:203b4129a213 36 void LCDMess(char *lMess, float dWait){
scohennm 0:203b4129a213 37 slcd.Home();
scohennm 0:203b4129a213 38 slcd.clear();
scohennm 0:203b4129a213 39 slcd.printf(lMess);
scohennm 0:203b4129a213 40 wait(dWait);
scohennm 0:203b4129a213 41 }
scohennm 0:203b4129a213 42
scohennm 0:203b4129a213 43
scohennm 0:203b4129a213 44 int main() {
scohennm 0:203b4129a213 45 float xAcc;
scohennm 0:203b4129a213 46 float yAcc;
scohennm 0:203b4129a213 47 float vector;
scohennm 0:203b4129a213 48 char lcdData[10]; //buffer needs places dor decimal pt and colon
scohennm 0:203b4129a213 49
scohennm 0:203b4129a213 50 #ifdef PRINTDBUG
scohennm 0:203b4129a213 51 pc.printf(PROGNAME);
scohennm 0:203b4129a213 52 #endif
scohennm 0:203b4129a213 53 // main loop forever
scohennm 0:203b4129a213 54 while(true) {
scohennm 0:203b4129a213 55
scohennm 0:203b4129a213 56 //Get accelerometer data - tilt angles minus offset for zero mark.
scohennm 0:203b4129a213 57 xAcc = abs(acc.getAccX());
scohennm 0:203b4129a213 58 yAcc = abs(acc.getAccY());
scohennm 0:203b4129a213 59 // Calulate vector sum of x and y reading.
scohennm 0:203b4129a213 60 vector = sqrt(pow(xAcc,2) + pow(yAcc,2));
scohennm 0:203b4129a213 61
scohennm 0:203b4129a213 62
scohennm 0:203b4129a213 63 #ifdef PRINTDBUG
scohennm 1:9340a340e588 64 pc.printf("xAcc = %f\r\n", xAcc);
scohennm 1:9340a340e588 65 pc.printf("yAcc = %f\r\n", yAcc);
scohennm 0:203b4129a213 66 pc.printf("vector = %f\r\n", vector);
scohennm 0:203b4129a213 67 #endif
scohennm 0:203b4129a213 68
scohennm 0:203b4129a213 69 sprintf (lcdData,"%4.3f",vector);
scohennm 0:203b4129a213 70 LCDMess(lcdData, DATATIME);
scohennm 0:203b4129a213 71 // Wait then do the whole thing again.
scohennm 0:203b4129a213 72 wait(DATATIME);
scohennm 0:203b4129a213 73 }
scohennm 0:203b4129a213 74 }