KBrat-SSD541-Midterm-Q2a

Dependencies:   SLCD TSI mbed

Fork of KBrat-SSD541-Midterm-Q2a by Keisha Brathwaite

Committer:
scohennm
Date:
Fri Sep 09 17:51:13 2016 +0000
Revision:
0:04499bc54bee
Child:
1:44dcf262c7dd
ssd3341 test of capacitive slider routines

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);
scohennm 0:04499bc54bee 11
scohennm 0:04499bc54bee 12 float tsidata;
scohennm 0:04499bc54bee 13
scohennm 0:04499bc54bee 14 void LCDMess(char *lMess){
scohennm 0:04499bc54bee 15 slcd.Home();
scohennm 0:04499bc54bee 16 slcd.clear();
scohennm 0:04499bc54bee 17 slcd.printf(lMess);
scohennm 0:04499bc54bee 18 }
scohennm 0:04499bc54bee 19
scohennm 0:04499bc54bee 20 int main(void) {
scohennm 0:04499bc54bee 21 char lcdData[LCDCHARLEN];
scohennm 0:04499bc54bee 22 PwmOut gled(LED_GREEN);
scohennm 0:04499bc54bee 23 PwmOut rled(LED_RED);
scohennm 0:04499bc54bee 24 pc.printf(PROGNAME);
scohennm 0:04499bc54bee 25 TSISensor tsi;
scohennm 0:04499bc54bee 26
scohennm 0:04499bc54bee 27 while (true) {
scohennm 0:04499bc54bee 28 tsidata = tsi.readPercentage();
scohennm 0:04499bc54bee 29 if (tsidata > TSILIMIT){
scohennm 0:04499bc54bee 30 gled = 0.0;
scohennm 0:04499bc54bee 31 rled = 0.0;
scohennm 0:04499bc54bee 32 }else {
scohennm 0:04499bc54bee 33 pc.printf("\n Position %f\n\r", tsidata);
scohennm 0:04499bc54bee 34 sprintf (lcdData,"%0.4f",tsidata);
scohennm 0:04499bc54bee 35 LCDMess(lcdData);
scohennm 0:04499bc54bee 36 gled = tsidata;
scohennm 0:04499bc54bee 37 rled = 1.0 - tsidata;
scohennm 0:04499bc54bee 38 }
scohennm 0:04499bc54bee 39 wait(DATAINTERVAL);
scohennm 0:04499bc54bee 40 }
scohennm 0:04499bc54bee 41 }