Jorn Dokter / Mbed 2 deprecated TEB_branch2

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Revision:
14:1a695fc45fc6
Parent:
13:f90e31c6af2b
Child:
15:95034d92bc76
--- a/main.cpp	Thu Oct 03 08:23:16 2019 +0000
+++ b/main.cpp	Thu Oct 03 09:04:34 2019 +0000
@@ -13,6 +13,9 @@
     //Motors
         
     //Sensors
+        //QEI Encoder1(D12,D13,NC,64,QEI::X2_ENCODING);
+        //QEI Encoder2(D14,D15,NC,64,QEI::X2_ENCODING);
+        //QEI Encoder3(D16,D17,NC,64,QEI::X2_ENCODING);
         
     //Buttons
         InterruptIn button1(SW2); //button on the side of the reset button
@@ -28,6 +31,10 @@
     volatile char ledcolor; //r is red, b is blue, g is green, t is bluegreen, p is purple
     volatile int errorCode;
     
+    //Ticker Timings
+        const float mainLoopT = 2; //Main Loopt Ticker wait
+        const float ledFlipperT = .5; //LED Flicker wait
+    
 
 
 //Tickers
@@ -70,18 +77,19 @@
             break;
         default:
             errorCode = 1;
-            pc.printf("Error 1: Color not defined");
+            CurrentState = FailState;
     }
     pc.printf("Color %c \r\n",ledcolor);
 }
 
+// SW2 = button1 state changing
 void Run_StateChangerButton1()
 {
     switch(CurrentState)
     {
-    case Startup:
-        CurrentState = CalibrationPhysical;
-        break;
+    case Startup: //From
+        CurrentState = CalibrationPhysical; //To
+        break; //Break from switch
     case CalibrationPhysical:
         CurrentState = CalibrationIdle;
         break;
@@ -102,7 +110,7 @@
         break;
     }
 }
-
+// SW3 = button2 state changing
 void Run_StateChangerButton2()
 {
     switch(CurrentState)
@@ -119,6 +127,8 @@
     }
 }
 
+
+//State functions
 void Run_Demo(void)
 {
     pc.printf("Starting Demo ...\r\n");
@@ -164,7 +174,7 @@
 
 void Run_FailState(void)
 {   
-    pc.printf("Starting Calibration FailState ... \r\n");
+    pc.printf("Error: %i",errorCode);
 }
 
 
@@ -211,7 +221,8 @@
             Run_FailState();
             break;
         default:
-            ledcolor='r';
+            CurrentState = FailState;
+            errorCode = 2;
             break;
     }
 }
@@ -241,8 +252,9 @@
     button2.rise(Run_StateChangerButton2);
     
     //Tickers
-        Main_Ticker.attach(mainloop,2);
-        Tick_Blinky.attach(FlipLED,.5);
+        Main_Ticker.attach(mainloop,mainLoopT);
+        wait(mainLoopT);
+        Tick_Blinky.attach(FlipLED,ledFlipperT);
     
     
     while(true)