Working reset, flipped logic

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Nhi by BAT

Revision:
17:08c575082052
Parent:
16:5c91af9b4e7c
Child:
18:d14bf57f435b
--- a/main.cpp	Wed Oct 25 14:31:33 2017 +0000
+++ b/main.cpp	Wed Oct 25 14:35:31 2017 +0000
@@ -25,7 +25,7 @@
 // add mode, reset buttons
 int start = 0;
 int submit = 0;
-int state = 2;
+int state = 0;
 int state2 = 0; // Button begins in up state
 ///int state2 = 2;
 int count = 0;
@@ -45,27 +45,38 @@
 // thread for the custom button
 void button_thread()
 {
+
     while(true) {
-        // button was up and is moving down, move servo in
-        //pc.printf("in button thread");
-        if (pb1 == 1 && state == 2) {
+        // state 0 - button is up, pb = 0
+        if (pb1 == 0 && state == 3) {
+            // nothing happens here, servo is still
+            state = 0;
+        }
+        // state 1 - button is moving down, pb = 1
+        if (pb1 == 1 && state == 0) {
             button1.moveServoIn();
             state = 1;
-            led1 = 0;
         }
-        // button was down and is being pushed again, move servo out
-        else if (pb1 == 1 && state == 1) {
+        // state 2 - button is down, pb = 0
+        if (pb1 == 0 && state == 1) {
+            // nothing happens here, servo is still
+            state = 2;
+        }
+        // state 3 - button is moving up, pb = 1
+        if (pb1 == 1 && state == 2) {
             button1.moveServoOut();
-            state = 2;
-            led1 = 1;
+            state = 3;
         }
-        Thread::wait(100); // wait till thread is done
+        // state 4 - handle debouncing while button is down
+        /*if (pb1 = 1 && state == 2) {
+            
+        }*/
+
     }
 }
 
 void button2_thread()
 {
-    // TODO: Add states
     while(true) {
         // state 0 - button is up, pb = 0
         if (pb2 == 0 && state2 == 3) {
@@ -95,24 +106,11 @@
             led3 = 1;
             led4 = 1;
         }
-        // state 4 - handle bouncing while button is down
+        // state 4 - handle debouncing while button is down
         /*if (pb2 = 1 && state2 == 2) {
             
         }*/
 
-        // button was up and is moving down, move servo in
-        /*if (pb2 == 1 && state2 == 2) {
-            button2.moveServoIn();
-            state2 = 1;
-            led2 = 0;
-        }
-        // button was down and is being pushed again, move servo out
-        else if (pb2 == 1 && state2 == 1) {
-            button2.moveServoOut();
-            state2 = 2;
-            led2 = 1;
-        }
-        */
         Thread::wait(100); // wait till thread is done
     }
 }