Words in Typing mode
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_Type_word by
Diff: main.cpp
- Revision:
- 43:fa8d0db68228
- Parent:
- 42:aa46c2be7dbb
--- a/main.cpp Mon Dec 04 19:40:28 2017 +0000 +++ b/main.cpp Tue Dec 05 03:34:17 2017 +0000 @@ -22,6 +22,9 @@ DigitalIn pb5 (p16); PwmOut myservo6(p26); DigitalIn pb6 (p15); +DigitalIn read (p29); +DigitalIn submit (p30); + //DigitalOut led1(LED1); //DigitalOut led3(LED3); @@ -44,8 +47,6 @@ // INITIALIZE VARIABLES // add mode, reset buttons -int start = 0; -int submit = 0; // Buttons begins in up state int state = 0; int state2 = 0; @@ -116,6 +117,8 @@ pb4.mode(PullUp); pb5.mode(PullUp); pb6.mode(PullUp); + read.mode(PullUp); + submit.mode(PullUp); wait(.001); // PARSE INPUT FILE FOR LETTERS AND WORDS @@ -173,7 +176,7 @@ //int type = 0; //TEXT-TO-SPEECH LOGIC - myTTS.volume(3); //max volume is 18 + myTTS.volume(18); //max volume is 18 myTTS.voice(2); @@ -201,13 +204,15 @@ string currword; int wordsize = sizeof(word)/sizeof(word[0]); - + //myTTS.speakf("SLet us now put these letters together to form words. Please reset buttons after each letter. Press down the submit button when done.\r"); // Send the desired string to convert to speech - myTTS.speakf("SPlease switch the device into typing mode. Press down the submit button when done.\r"); // Send the desired string to convert to speech + myTTS.speakf("SPlease switch the device into typing mode. After each word, press the submit button.\r"); // Send the desired string to convert to speech myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + while(read==1) {} // loop through each of the words for(int i = 0; i < wordsize; i++) { //iterate through the word array + //int i = 0; currword = word[i]; char currword1[3]; @@ -232,24 +237,33 @@ char wordinput[3]; // replace for loop with submit // while (!submit) { - - for (int j = 0; j < 3; j++) { + int j = 0; + int mysubmit = 0; + while(submit==0) { + //for (int j = 0; j <= 3; j++) { // check if all buttons were pressed char* braille; char* oldbraille; - wait(1); + wait(0.5); sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); //pc.printf("test %s ", braille); // wait for input - while (strcmp(braille, "111111") == 0) { + while ((strcmp(braille, "111111") == 0) && (submit==0)) { sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); } + if(submit==1) { + pc.printf("submit\n"); + break; + //mysubmit = 1; + } /*else { + pc.printf("submit button not pressed\n"); + }*/ // while buttons have not been released int oldsum = 0; @@ -265,10 +279,17 @@ // at the end of this, oldbraille contains the letter representation //pc.printf("%s ", oldbraille); + //if(mysubmit==0) { userinput = buttonarr.checkVal(oldbraille); - //pc.printf("%c ", userinput); + pc.printf("%c ", userinput); + //wordinput[j] = userinput; + //if(j <= 2) { wordinput[j] = userinput; + //} + j++; + //} } + //pc.printf("submit button pressed\n"); // check result of words incorrect = 0; @@ -291,7 +312,9 @@ } } } - + myTTS.speakf("SThis is the end of the module.\r"); // Send the desired string to convert to speech + myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + // MAIN THREAD while(true) {