Letters in typing mode
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_Type_letter by
Diff: main.cpp
- Revision:
- 42:bdb6f132a609
- Parent:
- 41:560ee7866781
diff -r 560ee7866781 -r bdb6f132a609 main.cpp --- a/main.cpp Sun Dec 03 23:44:27 2017 +0000 +++ b/main.cpp Mon Dec 04 19:57:53 2017 +0000 @@ -176,8 +176,9 @@ myTTS.volume(3); //max volume is 18 myTTS.voice(2); + // SETUP - /* buttonarr.setup(); //Reset servos so that buttons are up for typing mode + buttonarr.setup(); //Reset servos so that buttons are up for typing mode button1.setMode(1); button2.setMode(1); button3.setMode(1); @@ -322,120 +323,6 @@ } } - }*/ - -// WORD CODE - -// WORD COUNTER -// go through each word -// go through each letter in the word -// get user input -// when buttons reset - save previous letter -// loop until submit button is pressed -// compare words -// check what letters were wrong -// give wrong letters - correct spelling is... - - buttonarr.setup(); //Reset servos so that buttons are up for typing mode - - button1.setMode(1); - button2.setMode(1); - button3.setMode(1); - button4.setMode(1); - button5.setMode(1); - button6.setMode(1); - - 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.ready(); //ready waits for speech to finish from last command with a ":" response - - // loop through each of the words - for(int i = 0; i < wordsize; i++) { //iterate through the word array - currword = word[i]; - char currword1[3]; - - string presspin = "To type the word "; - presspin = presspin + word[i]; - presspin = presspin + ", type letters "; - for (int j = 0; j < currword.length(); j++) { - presspin = presspin + ", "+ currword[j]; - currword1[j] = currword[j]; - } - - myTTS.speakf("S%s\r", presspin); - myTTS.ready(); - - // loop through each of the letters - int incorrect = 1; - char userinput; - - // while(!submit) - while (incorrect == 1) { - - char wordinput[3]; - // replace for loop with submit - // while (!submit) { - - for (int j = 0; j < 3; j++) { - // check if all buttons were pressed - - char* braille; - char* oldbraille; - - wait(1); - - 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) { - sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), - !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); - } - - // while buttons have not been released - int oldsum = 0; - int sum = 0; - while ((strcmp(braille, "111111") != 0) && (oldsum <= sum)) { - oldbraille = braille; - oldsum = sum; - sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), - !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); - sum = button1.getPress() + button2.getPress() + button3.getPress() + button4.getPress() - + button5.getPress() + button6.getPress(); - } - - // at the end of this, oldbraille contains the letter representation - //pc.printf("%s ", oldbraille); - userinput = buttonarr.checkVal(oldbraille); - //pc.printf("%c ", userinput); - wordinput[j] = userinput; - } - - // check result of words - incorrect = 0; - for (int k = 0; k < 3; k++) { - //pc.printf("%c %c\n", currword[k], wordinput[k]); - if (currword1[k] != wordinput[k]) { // if any letter doesn't match - incorrect = 1; // spelling is wrong - } - } - - if (incorrect == 1) { - myTTS.speakf("SPlease try again! %s\r", presspin); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - //wait(2); - //incorrect = 1; - } else { - //wait(1); - myTTS.speakf("SGood job!\r"); - myTTS.ready(); //ready waits for speech to finish from last command with a ":" response - } - } } // MAIN THREAD