KBrat-SSD541-HW-5_1

Dependencies:   SLCD TSI mbed

Fork of kl46z_slider_v1 by Stanley Cohen

Committer:
tisbrat
Date:
Wed Sep 14 06:49:11 2016 +0000
Revision:
1:82153b535364
Parent:
0:04499bc54bee
KBrat-SSD541-HW-5_1

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
scohennm 0:04499bc54bee 5 #define LCDCHARLEN 10
scohennm 0:04499bc54bee 6 #define DATAINTERVAL 0.1
scohennm 0:04499bc54bee 7 #define PROGNAME "kl46z_slider_test_v1\n\r"
scohennm 0:04499bc54bee 8
scohennm 0:04499bc54bee 9 SLCD slcd; //define LCD display
scohennm 0:04499bc54bee 10 Serial pc(USBTX, USBRX);
tisbrat 1:82153b535364 11 Timer DataI;
scohennm 0:04499bc54bee 12
scohennm 0:04499bc54bee 13 float tsidata;
scohennm 0:04499bc54bee 14
scohennm 0:04499bc54bee 15 void LCDMess(char *lMess){
scohennm 0:04499bc54bee 16 slcd.Home();
scohennm 0:04499bc54bee 17 slcd.clear();
scohennm 0:04499bc54bee 18 slcd.printf(lMess);
scohennm 0:04499bc54bee 19 }
scohennm 0:04499bc54bee 20
tisbrat 1:82153b535364 21 void initialize_global_vars(){
tisbrat 1:82153b535364 22 DataI.start();
tisbrat 1:82153b535364 23 DataI.reset();
tisbrat 1:82153b535364 24 }
tisbrat 1:82153b535364 25
scohennm 0:04499bc54bee 26 int main(void) {
scohennm 0:04499bc54bee 27 char lcdData[LCDCHARLEN];
scohennm 0:04499bc54bee 28 PwmOut gled(LED_GREEN);
scohennm 0:04499bc54bee 29 PwmOut rled(LED_RED);
scohennm 0:04499bc54bee 30 pc.printf(PROGNAME);
scohennm 0:04499bc54bee 31 TSISensor tsi;
scohennm 0:04499bc54bee 32
scohennm 0:04499bc54bee 33 while (true) {
scohennm 0:04499bc54bee 34 tsidata = tsi.readPercentage();
scohennm 0:04499bc54bee 35 if (tsidata > TSILIMIT){
scohennm 0:04499bc54bee 36 gled = 0.0;
scohennm 0:04499bc54bee 37 rled = 0.0;
scohennm 0:04499bc54bee 38 }else {
scohennm 0:04499bc54bee 39 pc.printf("\n Position %f\n\r", tsidata);
scohennm 0:04499bc54bee 40 sprintf (lcdData,"%0.4f",tsidata);
scohennm 0:04499bc54bee 41 LCDMess(lcdData);
scohennm 0:04499bc54bee 42 gled = tsidata;
scohennm 0:04499bc54bee 43 rled = 1.0 - tsidata;
scohennm 0:04499bc54bee 44 }
tisbrat 1:82153b535364 45 // wait(DATAINTERVAL);
tisbrat 1:82153b535364 46 DataI.start();//Start timer
tisbrat 1:82153b535364 47 if (DataI > DATAINTERVAL){//if the timer data is greater than the data internval
tisbrat 1:82153b535364 48 DataI.reset();//Reset timer
tisbrat 1:82153b535364 49 }
tisbrat 1:82153b535364 50
tisbrat 1:82153b535364 51 if (tsidata = tsidata + 0.01){ //if the touch pos value is increased by 0.01
tisbrat 1:82153b535364 52 pc.printf("\n Position value increased by 0.01: \n\r", tsidata); //then print the position value increase
tisbrat 1:82153b535364 53 }
scohennm 0:04499bc54bee 54 }
scohennm 0:04499bc54bee 55 }