Homework 5.1

Dependencies:   SLCD TSI mbed

Fork of kl46z_slider_v1 by Stanley Cohen

Files at this revision

API Documentation at this revision

Comitter:
kennylujan42
Date:
Wed Sep 14 03:55:50 2016 +0000
Parent:
0:04499bc54bee
Commit message:
Homework 5.1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 04499bc54bee -r c17caef3dfff main.cpp
--- a/main.cpp	Fri Sep 09 17:51:13 2016 +0000
+++ b/main.cpp	Wed Sep 14 03:55:50 2016 +0000
@@ -8,6 +8,9 @@
 
 SLCD slcd; //define LCD display
 Serial pc(USBTX, USBRX);
+Ticker tick;
+
+volatile bool ticked;
 
 float tsidata;
 
@@ -17,25 +20,36 @@
         slcd.printf(lMess);
 }
 
+void tickFunction( void ) {
+    ticked = true;
+}
+
 int main(void) {
+    ticked = false;
+    tick.attach(&tickFunction, 0.10);
     char lcdData[LCDCHARLEN];
     PwmOut gled(LED_GREEN);
     PwmOut rled(LED_RED);
     pc.printf(PROGNAME);
     TSISensor tsi;
 
-     while (true) {
+     while (1) {
         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(ticked){
+            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;
+            
+            }
+            //wait(DATAINTERVAL);
+            ticked = false;
         }
-            wait(DATAINTERVAL);
     }
 }
\ No newline at end of file