first attempt at 5.1 homework. Swapped out wait function with a timer, and set up a statement to only print to terminal upon a 0.01 change in reading from the touch sensor. - CKM
Revision 0:bbc3f78d8ad5, committed 2016-09-14
- Comitter:
- CKMonroe
- Date:
- Wed Sep 14 04:38:58 2016 +0000
- Commit message:
- first attempt at 5.1 homework
Changed in this revision
diff -r 000000000000 -r bbc3f78d8ad5 SLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SLCD.lib Wed Sep 14 04:38:58 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/SLCD/#ef2b3b7f1b01
diff -r 000000000000 -r bbc3f78d8ad5 TSI.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TSI.lib Wed Sep 14 04:38:58 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/TSI/#1a60ef257879
diff -r 000000000000 -r bbc3f78d8ad5 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Sep 14 04:38:58 2016 +0000 @@ -0,0 +1,60 @@ +#include "mbed.h" +#include "TSISensor.h" +#include "SLCD.h" +#define TSILIMIT 0.99 +#define LCDCHARLEN 10 +#define DATAINTERVAL 0.1 +#define PROGNAME "kl46z_slider_test_v1_modified\n\r" + +SLCD slcd; //define LCD display +Serial pc(USBTX, USBRX); + +Timer readTimer; //timer to use instead of wait function + +float tsidata; + +float oldtsidata = 0.0; //variable to hold data for comparison + +void LCDMess(char *lMess){ + slcd.Home(); + slcd.clear(); + slcd.printf(lMess); +} + +int main(void) { + char lcdData[LCDCHARLEN]; + PwmOut gled(LED_GREEN); + PwmOut rled(LED_RED); + pc.printf(PROGNAME); + TSISensor tsi; + + readTimer.start(); + readTimer.reset(); + + while (true) { + if (readTimer > DATAINTERVAL){ //use if statement instead of wait + tsidata = tsi.readPercentage(); + if (tsidata > TSILIMIT){ + gled = 0.0; + rled = 0.0; + }else { + //have the terminal show info only if the data has changed by 0.01. + //would have perferred to use abs() function here but it did not + //seem to support importing math libraries -CKM + if ( (tsidata - oldtsidata) >= 0.01 || (oldtsidata - tsidata >= 0.01) ){ + pc.printf("\n Position %f\n\r", tsidata); + } + sprintf (lcdData,"%0.4f",tsidata); + LCDMess(lcdData); + gled = tsidata; + rled = 1.0 - tsidata; + }//end if-else statement + + oldtsidata = tsidata; + + readTimer.reset(); + }//end while loop + + //wait(DATAINTERVAL); + } +} \ No newline at end of file
diff -r 000000000000 -r bbc3f78d8ad5 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Sep 14 04:38:58 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897 \ No newline at end of file