Modified from original code

Dependencies:   SLCD TSI mbed

Fork of kl46z_slider_v1 by Stanley Cohen

Committer:
Raiden817
Date:
Wed Sep 14 17:57:25 2016 +0000
Revision:
1:90a2fe893338
Parent:
0:04499bc54bee
modified using original code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scohennm 0:04499bc54bee 1 #include "mbed.h"
scohennm 0:04499bc54bee 2 #include "TSISensor.h"
scohennm 0:04499bc54bee 3 #include "SLCD.h"
scohennm 0:04499bc54bee 4 #define TSILIMIT 0.99
Raiden817 1:90a2fe893338 5 #define PRINTDELTA 0.01
scohennm 0:04499bc54bee 6 #define LCDCHARLEN 10
scohennm 0:04499bc54bee 7 #define DATAINTERVAL 0.1
scohennm 0:04499bc54bee 8 #define PROGNAME "kl46z_slider_test_v1\n\r"
scohennm 0:04499bc54bee 9
scohennm 0:04499bc54bee 10 SLCD slcd; //define LCD display
scohennm 0:04499bc54bee 11 Serial pc(USBTX, USBRX);
scohennm 0:04499bc54bee 12
Raiden817 1:90a2fe893338 13 Timer dataTimer;
scohennm 0:04499bc54bee 14 float tsidata;
scohennm 0:04499bc54bee 15
Raiden817 1:90a2fe893338 16 void initialize_global_vars(){
Raiden817 1:90a2fe893338 17 pc.printf(PROGNAME);
Raiden817 1:90a2fe893338 18
Raiden817 1:90a2fe893338 19 dataTimer.start();
Raiden817 1:90a2fe893338 20 dataTimer.reset();
Raiden817 1:90a2fe893338 21 }
Raiden817 1:90a2fe893338 22
scohennm 0:04499bc54bee 23 void LCDMess(char *lMess){
scohennm 0:04499bc54bee 24 slcd.Home();
scohennm 0:04499bc54bee 25 slcd.clear();
scohennm 0:04499bc54bee 26 slcd.printf(lMess);
scohennm 0:04499bc54bee 27 }
scohennm 0:04499bc54bee 28
scohennm 0:04499bc54bee 29 int main(void) {
Raiden817 1:90a2fe893338 30 float lastTouch = 0.0;
scohennm 0:04499bc54bee 31 char lcdData[LCDCHARLEN];
scohennm 0:04499bc54bee 32 PwmOut gled(LED_GREEN);
scohennm 0:04499bc54bee 33 PwmOut rled(LED_RED);
scohennm 0:04499bc54bee 34 pc.printf(PROGNAME);
scohennm 0:04499bc54bee 35 TSISensor tsi;
scohennm 0:04499bc54bee 36
Raiden817 1:90a2fe893338 37 initialize_global_vars();
Raiden817 1:90a2fe893338 38
scohennm 0:04499bc54bee 39 while (true) {
Raiden817 1:90a2fe893338 40 if (dataTimer.read() > DATAINTERVAL) {
Raiden817 1:90a2fe893338 41 dataTimer.reset();
Raiden817 1:90a2fe893338 42 tsidata = tsi.readPercentage();
Raiden817 1:90a2fe893338 43 if (tsidata > TSILIMIT){
Raiden817 1:90a2fe893338 44 gled = 0.0;
Raiden817 1:90a2fe893338 45 rled = 0.0;
Raiden817 1:90a2fe893338 46 }else {
Raiden817 1:90a2fe893338 47 if (fabs(tsidata - lastTouch)< PRINTDELTA) {
Raiden817 1:90a2fe893338 48 pc.printf("\n Position %f\n\r", tsidata);
Raiden817 1:90a2fe893338 49 }
Raiden817 1:90a2fe893338 50 sprintf (lcdData,"%0.4f",tsidata);
Raiden817 1:90a2fe893338 51 LCDMess(lcdData);
Raiden817 1:90a2fe893338 52 gled = tsidata;
Raiden817 1:90a2fe893338 53 rled = 1.0 - tsidata;
Raiden817 1:90a2fe893338 54 }
Raiden817 1:90a2fe893338 55 lastTouch = tsidata;
scohennm 0:04499bc54bee 56 }
scohennm 0:04499bc54bee 57 }
scohennm 0:04499bc54bee 58 }