Working read code with mode button

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Testnew by BAT

Revision:
20:d14bf57f435b
Parent:
19:08c575082052
Child:
21:ceac47be2e64
diff -r 08c575082052 -r d14bf57f435b main.cpp
--- a/main.cpp	Wed Oct 25 14:35:31 2017 +0000
+++ b/main.cpp	Fri Oct 27 13:34:49 2017 +0000
@@ -9,9 +9,18 @@
 DigitalIn pb1 (p20);
 PwmOut myservo2(p22);
 DigitalIn pb2 (p19);
-DigitalOut led1(LED1);
-DigitalOut led3(LED3);
-DigitalOut led4(LED4);
+PwmOut myservo3(p23);
+DigitalIn pb3 (p18);
+PwmOut myservo4(p24);
+DigitalIn pb4 (p17);
+PwmOut myservo5(p25);
+DigitalIn pb5 (p16);
+PwmOut myservo6(p26);
+DigitalIn pb6 (p15);
+
+//DigitalOut led1(LED1);
+//DigitalOut led3(LED3);
+//DigitalOut led4(LED4);
 
 //AnalogIn linpot(p20);
 //Serial pc(USBTX, USBRX);
@@ -20,14 +29,22 @@
 //wave_player waver(&DACout);
 button button1(myservo, pb1);
 button button2(myservo2, pb2);
+button button3(myservo3, pb3);
+button button4(myservo4, pb4);
+button button5(myservo5, pb5);
+button button6(myservo6, pb6);
 
 // INITIALIZE VARIABLES
 // add mode, reset buttons
 int start = 0;
 int submit = 0;
+// Buttons begins in up state
 int state = 0;
-int state2 = 0; // Button begins in up state
-///int state2 = 2;
+int state2 = 0;
+int state3 = 0;
+int state4 = 0;
+int state5 = 0;
+int state6 = 0;
 int count = 0;
 
 // FUNCTIONS
@@ -43,9 +60,10 @@
 // THREADS
 
 // thread for the custom button
+//int count = 0;
+
 void button_thread()
 {
-
     while(true) {
         // state 0 - button is up, pb = 0
         if (pb1 == 0 && state == 3) {
@@ -69,9 +87,8 @@
         }
         // state 4 - handle debouncing while button is down
         /*if (pb1 = 1 && state == 2) {
-            
+            count++;
         }*/
-
     }
 }
 
@@ -82,29 +99,29 @@
         if (pb2 == 0 && state2 == 3) {
             // nothing happens here, servo is still
             state2 = 0;
-            led3 = 0;
-            led4 = 0;
+            //led3 = 0;
+            //led4 = 0;
         }
         // state 1 - button is moving down, pb = 1
         if (pb2 == 1 && state2 == 0) {
             button2.moveServoIn();
             state2 = 1;
-            led3 = 0;
-            led4 = 1;
+            //led3 = 0;
+            //led4 = 1;
         }
         // state 2 - button is down, pb = 0
         if (pb2 == 0 && state2 == 1) {
             // nothing happens here, servo is still
             state2 = 2;
-            led3 = 1;
-            led4 = 0;
+            //led3 = 1;
+            //led4 = 0;
         }
         // state 3 - button is moving up, pb = 1
         if (pb2 == 1 && state2 == 2) {
             button2.moveServoOut();
             state2 = 3;
-            led3 = 1;
-            led4 = 1;
+            //led3 = 1;
+            //led4 = 1;
         }
         // state 4 - handle debouncing while button is down
         /*if (pb2 = 1 && state2 == 2) {
@@ -115,6 +132,135 @@
     }
 }
 
+// thread for the custom button
+void button3_thread()
+{
+    while(true) {
+        // state 0 - button is up, pb = 0
+        if (pb3 == 0 && state3 == 3) {
+            // nothing happens here, servo is still
+            state3 = 0;
+        }
+        // state 1 - button is moving down, pb = 1
+        if (pb3 == 1 && state3 == 0) {
+            button3.moveServoIn();
+            state3 = 1;
+        }
+        // state 2 - button is down, pb = 0
+        if (pb3 == 0 && state3 == 1) {
+            // nothing happens here, servo is still
+            state3 = 2;
+        }
+        // state 3 - button is moving up, pb = 1
+        if (pb3 == 1 && state3 == 2) {
+            button3.moveServoOut();
+            state3 = 3;
+        }
+        // state 4 - handle debouncing while button is down
+        /*if (pb3 = 1 && state3 == 2) {
+            
+        }*/
+
+    }
+}
+
+// thread for the custom button
+void button4_thread()
+{
+    while(true) {
+        // state 0 - button is up, pb = 0
+        if (pb4 == 0 && state4 == 3) {
+            // nothing happens here, servo is still
+            state4 = 0;
+        }
+        // state 1 - button is moving down, pb = 1
+        if (pb4 == 1 && state4 == 0) {
+            button4.moveServoIn();
+            state4 = 1;
+        }
+        // state 2 - button is down, pb = 0
+        if (pb4 == 0 && state4 == 1) {
+            // nothing happens here, servo is still
+            state4 = 2;
+        }
+        // state 3 - button is moving up, pb = 1
+        if (pb4 == 1 && state4 == 2) {
+            button4.moveServoOut();
+            state4 = 3;
+        }
+        // state 4 - handle debouncing while button is down
+        /*if (pb4 = 1 && state4 == 2) {
+            
+        }*/
+
+    }
+}
+
+// thread for the custom button
+void button5_thread()
+{
+
+    while(true) {
+        // state 0 - button is up, pb = 0
+        if (pb5 == 0 && state5 == 3) {
+            // nothing happens here, servo is still
+            state5 = 0;
+        }
+        // state 1 - button is moving down, pb = 1
+        if (pb5 == 1 && state5 == 0) {
+            button5.moveServoIn();
+            state5 = 1;
+        }
+        // state 2 - button is down, pb = 0
+        if (pb5 == 0 && state5 == 1) {
+            // nothing happens here, servo is still
+            state5 = 2;
+        }
+        // state 3 - button is moving up, pb = 1
+        if (pb5 == 1 && state5 == 2) {
+            button5.moveServoOut();
+            state5 = 3;
+        }
+        // state 4 - handle debouncing while button is down
+        /*if (pb5 = 1 && state5 == 2) {
+            
+        }*/
+
+    }
+}
+
+// thread for the custom button
+void button6_thread()
+{
+    while(true) {
+        // state 0 - button is up, pb = 0
+        if (pb6 == 0 && state6 == 3) {
+            // nothing happens here, servo is still
+            state6 = 0;
+        }
+        // state 1 - button is moving down, pb = 1
+        if (pb6 == 1 && state6 == 0) {
+            button6.moveServoIn();
+            state6 = 1;
+        }
+        // state 2 - button is down, pb = 0
+        if (pb6 == 0 && state6 == 1) {
+            // nothing happens here, servo is still
+            state6 = 2;
+        }
+        // state 3 - button is moving up, pb = 1
+        if (pb6 == 1 && state6 == 2) {
+            button6.moveServoOut();
+            state6 = 3;
+        }
+        // state 4 - handle debouncing while button is down
+        /*if (pb6 = 1 && state6 == 2) {
+            
+        }*/
+
+    }
+}
+
 void submit_thread()
 {
     Thread::wait(500); // wait till thread is done
@@ -137,6 +283,10 @@
     // pull up the pushbutton to prevent bouncing
     pb1.mode(PullUp);
     pb2.mode(PullUp);
+    pb3.mode(PullUp);
+    pb4.mode(PullUp);
+    pb5.mode(PullUp);
+    pb6.mode(PullUp);
     wait(.001);
 
     // servo begins at 30 degrees
@@ -149,13 +299,41 @@
         myservo2 = i/100.0;
         wait(0.01);
     }
+    
+    for(int i=0; i<=3; i++) {
+        myservo3 = i/100.0;
+        wait(0.01);
+    }
+    
+    for(int i=0; i<=3; i++) {
+        myservo4 = i/100.0;
+        wait(0.01);
+    }
+    
+    for(int i=0; i<=3; i++) {
+        myservo5 = i/100.0;
+        wait(0.01);
+    }
 
-    led1 = 1;
+    for(int i=0; i<=3; i++) {
+        myservo6 = i/100.0;
+        wait(0.01);
+    }
+    
+    //led1 = 1;
     //led2 = 1;
-    Thread t3(button_thread);
-    Thread t4(button2_thread);
-    t3.start(button_thread);
-    t4.start(button2_thread);
+    Thread t1(button_thread);
+    Thread t2(button2_thread);
+    Thread t3(button3_thread);
+    Thread t4(button4_thread);
+    Thread t5(button5_thread);
+    Thread t6(button6_thread);
+    t1.start(button_thread);
+    t2.start(button2_thread);
+    t3.start(button3_thread);
+    t4.start(button4_thread);
+    t5.start(button5_thread);
+    t6.start(button6_thread);
 
     // start threads for reset, mode, start
     //Thread t1(start_thread);
@@ -185,6 +363,7 @@
     //if (linpot < 0.5) {
     //float potval = linpot;
     //pc.printf("linear pot: %f\n", potval);
+    
     // MAIN THREAD
     while(true) {
         Thread::wait(500); // wait till thread is done