Modified from original code

Dependencies:   SLCD TSI mbed

Fork of kl46z_slider_v1 by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
Raiden817
Date:
Wed Sep 14 17:57:25 2016 +0000
Parent:
0:04499bc54bee
Commit message:
modified using original code

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 04499bc54bee -r 90a2fe893338 main.cpp
--- a/main.cpp	Fri Sep 09 17:51:13 2016 +0000
+++ b/main.cpp	Wed Sep 14 17:57:25 2016 +0000
@@ -2,6 +2,7 @@
 #include "TSISensor.h"
 #include "SLCD.h"
 #define TSILIMIT 0.99
+#define PRINTDELTA 0.01
 #define LCDCHARLEN 10
 #define DATAINTERVAL 0.1
 #define PROGNAME "kl46z_slider_test_v1\n\r"
@@ -9,8 +10,16 @@
 SLCD slcd; //define LCD display
 Serial pc(USBTX, USBRX);
 
+Timer dataTimer;
 float tsidata;
 
+void initialize_global_vars(){
+    pc.printf(PROGNAME);
+    
+    dataTimer.start();
+    dataTimer.reset();
+}
+
 void LCDMess(char *lMess){
         slcd.Home();
         slcd.clear();
@@ -18,24 +27,32 @@
 }
 
 int main(void) {
+    float lastTouch = 0.0;
     char lcdData[LCDCHARLEN];
     PwmOut gled(LED_GREEN);
     PwmOut rled(LED_RED);
     pc.printf(PROGNAME);
     TSISensor tsi;
 
+    initialize_global_vars();
+
      while (true) {
-        tsidata = tsi.readPercentage();
-        if (tsidata > TSILIMIT){
-            gled = 0.0;
-            rled = 0.0;
-        }else {
-            pc.printf("\n Position %f\n\r", tsidata);
-            sprintf (lcdData,"%0.4f",tsidata);  
-            LCDMess(lcdData);  
-            gled = tsidata;
-            rled = 1.0 - tsidata;
+        if (dataTimer.read() > DATAINTERVAL) {
+            dataTimer.reset();
+            tsidata = tsi.readPercentage();
+            if (tsidata > TSILIMIT){
+                gled = 0.0;
+                rled = 0.0;
+            }else {
+                if (fabs(tsidata - lastTouch)< PRINTDELTA) {
+                  pc.printf("\n Position %f\n\r", tsidata);              
+                }
+                sprintf (lcdData,"%0.4f",tsidata);  
+                LCDMess(lcdData);
+                gled = tsidata;
+                rled = 1.0 - tsidata;               
+            }
+            lastTouch = tsidata;
         }
-            wait(DATAINTERVAL);
     }
 }
\ No newline at end of file