Words in Typing mode FINAL

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_Type_word_FINAL by Azra Ismail

Revision:
39:8cc80f0b4398
Parent:
33:3090ec93b4aa
Child:
41:560ee7866781
--- a/button.cpp	Sat Dec 02 01:49:48 2017 +0000
+++ b/button.cpp	Sat Dec 02 23:53:06 2017 +0000
@@ -9,7 +9,7 @@
 
 // button constructor
 button::button(PwmOut servo, DigitalIn pb, int id)
-    : servo(servo), pb(pb), state(0), press(0), id(id) {}
+    : servo(servo), pb(pb), state(0), press(0), id(id), type(0) {}
 /*button::button(PwmOut servo, DigitalIn pb, AnalogIn lp)
     : servo(servo), pb(pb), linpot(lp), press(0), state(0) {}
 */
@@ -124,41 +124,41 @@
     led4 = 0;
 }
 
-int button::updateState()
+// get servo pin
+void button::setMode(int mymode)
 {
-    //myled = 0;
-    // state 0 - button is up, pb = 0
-    if (pb == 0 && state == 3) {
-        // nothing happens here, servo is still
-        state = 0;
-    }
-    // state 1 - button is moving down, pb = 1
-    if (pb == 1 && state == 0) {
-        moveServoIn();
-        state = 1;
-        press = 1;
+    type = mymode;
+}
 
-        // Speaker says stuff
-        /*myTTS.volume(18); //max volume
-        myTTS.speakf("S");//Speak command starts with "S"
-        myTTS.speakf("Hey, you pressed a pin!");  // Send the desired string to convert to speech
-        myTTS.speakf("\r"); //marks end of speak command*/
-    }
-    // state 2 - button is down, pb = 0
-    if (pb == 0 && state == 1) {
-        // nothing happens here, servo is still
-        state = 2;
+int button::updateState()
+{    if (type == 0) {
+        //myled = 0;
+        // state 0 - button is up, pb = 0
+        if (pb == 0 && state == 3) {
+            // nothing happens here, servo is still
+            state = 0;
+        }
+        // state 1 - button is moving down, pb = 1
+        if (pb == 1 && state == 0) {
+            moveServoIn();
+            state = 1;
+            press = 1;
+        }
+        // state 2 - button is down, pb = 0
+        if (pb == 0 && state == 1) {
+            // nothing happens here, servo is still
+            state = 2;
+        }
+        // state 3 - button is moving up, pb = 1
+        if (pb == 1 && state == 2) {
+            moveServoOut();
+            state = 3;
+            press = 0;
+        }
+    } else {
+        state = pb;
+        press = pb;
     }
-    // state 3 - button is moving up, pb = 1
-    if (pb == 1 && state == 2) {
-        moveServoOut();
-        state = 3;
-        press = 0;
-    }
-    // state 4 - handle debouncing while button is down
-    /*if (pb1 = 1 && state == 2) {
-        count++;
-    }*/
     return state;
 }