SSD541_HW5.1

Dependencies:   SLCD TSI mbed

Fork of kl46z_slider_v1 by Stanley Cohen

Revision:
1:c3cfa0fd8ad7
Parent:
0:04499bc54bee
--- a/main.cpp	Fri Sep 09 17:51:13 2016 +0000
+++ b/main.cpp	Wed Sep 14 14:29:22 2016 +0000
@@ -3,7 +3,7 @@
 #include "SLCD.h"
 #define TSILIMIT 0.99
 #define LCDCHARLEN 10
-#define DATAINTERVAL 0.1
+#define DATAINTERVAL 0.01
 #define PROGNAME "kl46z_slider_test_v1\n\r"
 
 SLCD slcd; //define LCD display
@@ -11,31 +11,40 @@
 
 float tsidata;
 
-void LCDMess(char *lMess){
-        slcd.Home();
-        slcd.clear();
-        slcd.printf(lMess);
+void LCDMess(char *lMess)
+{
+    slcd.Home();
+    slcd.clear();
+    slcd.printf(lMess);
 }
 
-int main(void) {
+Timer WaitTimer;
+
+int main(void)
+{
     char lcdData[LCDCHARLEN];
     PwmOut gled(LED_GREEN);
     PwmOut rled(LED_RED);
     pc.printf(PROGNAME);
     TSISensor tsi;
+    WaitTimer.start();
+    WaitTimer.reset();
 
-     while (true) {
+    while (true) {
+        WaitTimer.start();
         tsidata = tsi.readPercentage();
-        if (tsidata > TSILIMIT){
+        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;
+        } else {
+            if(WaitTimer > DATAINTERVAL){
+                pc.printf("\n Position %f\n\r", tsidata);
+                sprintf (lcdData,"%0.4f",tsidata);
+                LCDMess(lcdData);
+                gled = tsidata;
+                rled = 1.0 - tsidata;
+                WaitTimer.reset();
+            }
         }
-            wait(DATAINTERVAL);
     }
 }
\ No newline at end of file