Working read code with mode button

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Testnew by BAT

Revision:
18:5c91af9b4e7c
Parent:
17:7e9308d14faa
Child:
19:08c575082052
--- a/main.cpp	Sun Oct 22 22:34:06 2017 +0000
+++ b/main.cpp	Wed Oct 25 14:31:33 2017 +0000
@@ -10,7 +10,8 @@
 PwmOut myservo2(p22);
 DigitalIn pb2 (p19);
 DigitalOut led1(LED1);
-DigitalOut led2(LED4);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
 
 //AnalogIn linpot(p20);
 //Serial pc(USBTX, USBRX);
@@ -24,9 +25,9 @@
 // add mode, reset buttons
 int start = 0;
 int submit = 0;
-// FIX THIS: button up: state = 2, button halfway: state = 0; button down: state = 1
 int state = 2;
-int state2 = 2;
+int state2 = 0; // Button begins in up state
+///int state2 = 2;
 int count = 0;
 
 // FUNCTIONS
@@ -67,30 +68,40 @@
     // TODO: Add states
     while(true) {
         // state 0 - button is up, pb = 0
-        // if (pb == 0 && state == 3) {
+        if (pb2 == 0 && state2 == 3) {
             // nothing happens here, servo is still
-            // state2 = 0;
-        //    }
+            state2 = 0;
+            led3 = 0;
+            led4 = 0;
+        }
         // state 1 - button is moving down, pb = 1
-        // if (pb == 1 && state == 0) {
-            //button2.moveServoIn();
-            //state2 = 1;
-        //    }
+        if (pb2 == 1 && state2 == 0) {
+            button2.moveServoIn();
+            state2 = 1;
+            led3 = 0;
+            led4 = 1;
+        }
         // state 2 - button is down, pb = 0
-        // if (pb == 0 && state == 1) {
+        if (pb2 == 0 && state2 == 1) {
             // nothing happens here, servo is still
-            // state2 = 2;
-        //    }
+            state2 = 2;
+            led3 = 1;
+            led4 = 0;
+        }
         // state 3 - button is moving up, pb = 1
-        // if (pb == 1 && state == 2) {
-            //button2.moveServoOut();
-            //state2 = 3;
-        //    }
+        if (pb2 == 1 && state2 == 2) {
+            button2.moveServoOut();
+            state2 = 3;
+            led3 = 1;
+            led4 = 1;
+        }
         // state 4 - handle bouncing while button is down
-
+        /*if (pb2 = 1 && state2 == 2) {
+            
+        }*/
 
         // button was up and is moving down, move servo in
-        if (pb2 == 1 && state2 == 2) {
+        /*if (pb2 == 1 && state2 == 2) {
             button2.moveServoIn();
             state2 = 1;
             led2 = 0;
@@ -101,6 +112,7 @@
             state2 = 2;
             led2 = 1;
         }
+        */
         Thread::wait(100); // wait till thread is done
     }
 }
@@ -125,9 +137,9 @@
 {
     // SETUP
     // pull up the pushbutton to prevent bouncing
-    //pb1.mode(PullUp);
-    //pb2.mode(PullUp);
-    //wait(.001);
+    pb1.mode(PullUp);
+    pb2.mode(PullUp);
+    wait(.001);
 
     // servo begins at 30 degrees
     // replace with a button setup function
@@ -141,7 +153,7 @@
     }
 
     led1 = 1;
-    led2 = 1;
+    //led2 = 1;
     Thread t3(button_thread);
     Thread t4(button2_thread);
     t3.start(button_thread);