Numero Uno / Mbed 2 deprecated TheProgram

Dependencies:   EMG HIDScope PID QEI mbed TextLCD

Revision:
9:3e19a344c025
Parent:
8:b0971033dc41
Child:
10:819fb5288aa0
--- a/main.cpp	Mon Oct 26 11:15:31 2015 +0000
+++ b/main.cpp	Mon Oct 26 14:26:13 2015 +0000
@@ -1,5 +1,6 @@
 //****************************************************************************/
 // Includes
+#include <string>
 #include "TextLCD.h"
 #include "mbed.h"
 #include "PID.h"
@@ -9,6 +10,10 @@
 #include "inits.h" // all globals, pin and variable initialization 
 #include "EMG.h"
 
+void setLcdFlag(){
+    lcdGoFlag=true;   
+    
+}
 void setGoFlag(){
     if (goFlag==true){
         //pc.printf("rate too high, error in setGoFlag \n\r");
@@ -19,7 +24,7 @@
 void initpositiongo(){
     if(initposition_go){initposition_go=false;}
     else {initposition_go=true;}
-    pc.printf("initposition: %d",initposition_go);
+    pc.printf("initposition: %d \n\r",initposition_go);
 }
 
 void systemStart(){
@@ -57,11 +62,14 @@
     
     // interrupts
     motorControlTicker.attach(&setGoFlag, RATE);
+    lcdTicker.attach(&setLcdFlag,0.2);
     cali_button.rise(&calibratego);
     initpositionButton.rise(&initpositiongo);
     startButton.rise(&systemStart);
     stopButton.rise(&systemStop);
     
+    playTimer.start();
+    
     while (true){
         if (calibrate_go==true){
             lcd.cls();
@@ -87,7 +95,8 @@
                 //pc.printf("initposition_go, left:%f, leftAngle:%f, right:%f, rightAngle: %f",leftRequest, leftAngle, rightRequest, rightAngle);
             }
             else {
-                sample_filter();      
+                sample_filter();   
+                y2=0;   
                 // determine if forward or backward signal is stronger
                 if (y1 > y2){
                     horrequest = y1; 
@@ -128,16 +137,16 @@
                 currentY = tan(leftAngle*M_PI/180)*currentX;
                 
                 // restrict motion if edges are touched
-                if (edgeleft==0){pc.printf("hit left edge \n\r");
+                if (edgeleft==0){
                     if (horrequest < 0){horrequest=0; }
                 }
-                if (edgeright==0){pc.printf("hit right edge \n\r");
+                if (edgeright==0){
                     if (horrequest > 0){horrequest=0; }
                 }
-                if (edgetop==0){pc.printf("hit top edge \n\r");
+                if (edgetop==0){
                     if (verrequest > 0){verrequest=0; }
                 }
-                if (edgebottom==0){pc.printf("hit bottom edge \n\r");
+                if (edgebottom==0){
                     if (verrequest < 0){verrequest=0; }
                 }
                 
@@ -230,6 +239,43 @@
             leftMotor=0;
             rightMotor=0;
         }
+        if(lcdGoFlag==true){
+            text="";
+            text+="hor: ";
+            if(horrequest==-1){text+="<<";}
+            if(horrequest==-0.5){text+=" <";}
+            if(horrequest>=0){text+="  ";}
+            text+="0";
+            if(horrequest<=0){text+="  ";}
+            if(horrequest==0.5){text+="> ";}
+            if(horrequest==1){text+=">>";}
+        
+        
+            text+=" T:%d\n",playTimer.read();
+            
+            if(verrequest==-1){text+="<<";}
+            if(verrequest==-0.5){text+=" <";}
+            if(verrequest>=0){text+="  ";}
+            text+="0";
+            if(verrequest<=0){text+="  ";}
+            if(verrequest==0.5){text+="> ";}
+            if(verrequest==1){text+=">>";}
+            
+            text+" HIT:%d",0;
+            
+           
+            
+            char chartext[1024];
+            strcpy(chartext, text.c_str());
+            
+            pc.printf(chartext);
+             
+            lcd.cls();
+            lcd.printf(chartext);
+            
+            lcdGoFlag=false;
+            
+        }
     }
     
 }