Module 9 Super Team / Mbed 2 deprecated hookey_controller

Dependencies:   EMG1 PIDController1 compute mbed InBetweenController PinDetect QEI

Revision:
14:0a66bce6ee19
Parent:
11:46a859e526ca
Child:
16:b977ba7ed362
--- a/main.cpp	Wed Oct 28 13:46:56 2015 +0000
+++ b/main.cpp	Thu Oct 29 10:55:06 2015 +0000
@@ -10,13 +10,14 @@
 Ticker      sample_timer;
 Ticker      movement_timer;
 Ticker      calc_timer;
-PinDetect   cali(SW2);
-PinDetect   start(SW3);
+PinDetect   sRound(SW2);
+PinDetect   caliAndSS(SW3);
 bool        started = true;
 bool        go_motor = true;
 bool        go_tick = false;
 bool        go_sample = false;
 double      motorSpeed = 0.2;
+int         calibrated = 0;
 
 double      emg_out0, emg_out1, emg_out2;
 
@@ -147,8 +148,13 @@
 void goSample() { go_sample = true; }
 
 /* Function called by pressing the SW3 Button */
-void startAll()
+void calibrateAndStartStop()
 {
+    if(calibrated < 3) {
+        calibrated++;
+        emg_cal(calibrated);
+        return;   
+    }
     started = !started;
     if(started)
         movement_timer.attach(&goMotor, 0.01f);
@@ -160,8 +166,9 @@
 }
 
 /* Function called by pressing the SW2 Button */
-void calibrate()
+void startRound()
 {
+    if(calibrated < 3) return;
     sample_timer.attach(&goSample, 0.002);
     calc_timer.attach(&goTick, 0.15);
 }
@@ -170,13 +177,13 @@
 void init()
 {
     // Set the shutup and start buttons
-    start.mode(PullUp);
-    start.attach_deasserted(&startAll);
-    start.setSampleFrequency();
+    caliAndSS.mode(PullUp);
+    caliAndSS.attach_deasserted(&calibrateAndStartStop);
+    caliAndSS.setSampleFrequency();
 
-    cali.mode(PullUp);
-    cali.attach_deasserted(&calibrate);
-    cali.setSampleFrequency();
+    sRound.mode(PullUp);
+    sRound.attach_deasserted(&startRound);
+    sRound.setSampleFrequency();
 
     pc2.printf("Buttons done\r\n\r\n");
 }