Words in Typing mode
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_Type_word by
main.cpp@41:560ee7866781, 2017-12-03 (annotated)
- Committer:
- aismail1997
- Date:
- Sun Dec 03 23:44:27 2017 +0000
- Revision:
- 41:560ee7866781
- Parent:
- 40:85be3490d3a7
- Child:
- 42:aa46c2be7dbb
letter and write mode work independently;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aismail1997 | 0:9eda4611081a | 1 | #include "mbed.h" |
aismail1997 | 6:1aa86ad19af9 | 2 | #include "rtos.h" |
aismail1997 | 9:418a4437a693 | 3 | #include "SDFileSystem.h" |
aismail1997 | 10:21268d8bf979 | 4 | #include "button.h" |
aismail1997 | 19:ceac47be2e64 | 5 | #include "buttonArray.h" |
aismail1997 | 23:23970cf718ee | 6 | #include <string> |
aismail1997 | 23:23970cf718ee | 7 | #include <iostream> |
aismail1997 | 28:3c4ebc4fde0f | 8 | #include "emic2.h" |
aismail1997 | 23:23970cf718ee | 9 | |
aismail1997 | 23:23970cf718ee | 10 | using namespace std; |
aismail1997 | 3:9ed43e974156 | 11 | |
aismail1997 | 13:b80dde24e9bc | 12 | // DEFINE I/O |
aismail1997 | 0:9eda4611081a | 13 | PwmOut myservo(p21); |
aismail1997 | 0:9eda4611081a | 14 | DigitalIn pb1 (p20); |
aismail1997 | 14:581a3b02f4c3 | 15 | PwmOut myservo2(p22); |
aismail1997 | 14:581a3b02f4c3 | 16 | DigitalIn pb2 (p19); |
aismail1997 | 18:d14bf57f435b | 17 | PwmOut myservo3(p23); |
aismail1997 | 18:d14bf57f435b | 18 | DigitalIn pb3 (p18); |
aismail1997 | 18:d14bf57f435b | 19 | PwmOut myservo4(p24); |
aismail1997 | 18:d14bf57f435b | 20 | DigitalIn pb4 (p17); |
aismail1997 | 18:d14bf57f435b | 21 | PwmOut myservo5(p25); |
aismail1997 | 18:d14bf57f435b | 22 | DigitalIn pb5 (p16); |
aismail1997 | 18:d14bf57f435b | 23 | PwmOut myservo6(p26); |
aismail1997 | 18:d14bf57f435b | 24 | DigitalIn pb6 (p15); |
aismail1997 | 18:d14bf57f435b | 25 | |
aismail1997 | 18:d14bf57f435b | 26 | //DigitalOut led1(LED1); |
aismail1997 | 18:d14bf57f435b | 27 | //DigitalOut led3(LED3); |
aismail1997 | 22:6931917c70cd | 28 | //DigitalOut led4(LED4); |
aismail1997 | 14:581a3b02f4c3 | 29 | |
nnguyen45 | 32:e87bb6e83072 | 30 | //DigitalIn linpot(p9); |
nnguyen45 | 33:3090ec93b4aa | 31 | Serial pc(USBTX, USBRX); |
aismail1997 | 23:23970cf718ee | 32 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
aismail1997 | 21:c5df903f068a | 33 | //button button1(myservo, pb1, linpot); |
aismail1997 | 21:c5df903f068a | 34 | button button1(myservo, pb1, 1); |
aismail1997 | 21:c5df903f068a | 35 | button button2(myservo2, pb2, 2); |
aismail1997 | 21:c5df903f068a | 36 | button button3(myservo3, pb3, 3); |
aismail1997 | 21:c5df903f068a | 37 | button button4(myservo4, pb4, 4); |
aismail1997 | 21:c5df903f068a | 38 | button button5(myservo5, pb5, 5); |
aismail1997 | 21:c5df903f068a | 39 | button button6(myservo6, pb6, 6); |
aismail1997 | 4:cc181f8f2bd1 | 40 | |
aismail1997 | 19:ceac47be2e64 | 41 | buttonArray buttonarr(button1, button2, button3, button4, button5, button6); |
aismail1997 | 19:ceac47be2e64 | 42 | |
aismail1997 | 28:3c4ebc4fde0f | 43 | emic2 myTTS(p28, p27); //serial RX,TX pins to emic |
aismail1997 | 28:3c4ebc4fde0f | 44 | |
aismail1997 | 13:b80dde24e9bc | 45 | // INITIALIZE VARIABLES |
aismail1997 | 13:b80dde24e9bc | 46 | // add mode, reset buttons |
aismail1997 | 9:418a4437a693 | 47 | int start = 0; |
aismail1997 | 9:418a4437a693 | 48 | int submit = 0; |
aismail1997 | 18:d14bf57f435b | 49 | // Buttons begins in up state |
aismail1997 | 17:08c575082052 | 50 | int state = 0; |
aismail1997 | 18:d14bf57f435b | 51 | int state2 = 0; |
aismail1997 | 18:d14bf57f435b | 52 | int state3 = 0; |
aismail1997 | 18:d14bf57f435b | 53 | int state4 = 0; |
aismail1997 | 18:d14bf57f435b | 54 | int state5 = 0; |
aismail1997 | 18:d14bf57f435b | 55 | int state6 = 0; |
aismail1997 | 14:581a3b02f4c3 | 56 | int count = 0; |
aismail1997 | 6:1aa86ad19af9 | 57 | |
aismail1997 | 6:1aa86ad19af9 | 58 | // THREADS |
aismail1997 | 13:b80dde24e9bc | 59 | |
aismail1997 | 6:1aa86ad19af9 | 60 | void button_thread() |
aismail1997 | 4:cc181f8f2bd1 | 61 | { |
aismail1997 | 14:581a3b02f4c3 | 62 | while(true) { |
aismail1997 | 19:ceac47be2e64 | 63 | state = button1.updateState(); |
nnguyen45 | 33:3090ec93b4aa | 64 | state6 = button6.updateState(); |
nnguyen45 | 33:3090ec93b4aa | 65 | |
aismail1997 | 21:c5df903f068a | 66 | //led4 = button1.getLp(); |
aismail1997 | 19:ceac47be2e64 | 67 | Thread::wait(100); // wait till thread is done |
aismail1997 | 10:21268d8bf979 | 68 | } |
aismail1997 | 14:581a3b02f4c3 | 69 | } |
aismail1997 | 14:581a3b02f4c3 | 70 | |
aismail1997 | 14:581a3b02f4c3 | 71 | void button2_thread() |
aismail1997 | 14:581a3b02f4c3 | 72 | { |
aismail1997 | 14:581a3b02f4c3 | 73 | while(true) { |
aismail1997 | 19:ceac47be2e64 | 74 | state2 = button2.updateState(); |
aismail1997 | 40:85be3490d3a7 | 75 | //state5 = button5.updateState(); |
nnguyen45 | 32:e87bb6e83072 | 76 | Thread::wait(200); // wait till thread is done |
aismail1997 | 10:21268d8bf979 | 77 | } |
aismail1997 | 4:cc181f8f2bd1 | 78 | } |
aismail1997 | 4:cc181f8f2bd1 | 79 | |
aismail1997 | 18:d14bf57f435b | 80 | // thread for the custom button |
aismail1997 | 18:d14bf57f435b | 81 | void button3_thread() |
aismail1997 | 18:d14bf57f435b | 82 | { |
aismail1997 | 18:d14bf57f435b | 83 | while(true) { |
aismail1997 | 19:ceac47be2e64 | 84 | state3 = button3.updateState(); |
aismail1997 | 40:85be3490d3a7 | 85 | //state5 = button4.updateState(); |
nnguyen45 | 32:e87bb6e83072 | 86 | Thread::wait(200); // wait till thread is done |
aismail1997 | 18:d14bf57f435b | 87 | } |
aismail1997 | 18:d14bf57f435b | 88 | } |
aismail1997 | 18:d14bf57f435b | 89 | |
aismail1997 | 18:d14bf57f435b | 90 | // thread for the custom button |
aismail1997 | 18:d14bf57f435b | 91 | void button4_thread() |
aismail1997 | 18:d14bf57f435b | 92 | { |
aismail1997 | 18:d14bf57f435b | 93 | while(true) { |
aismail1997 | 19:ceac47be2e64 | 94 | state4 = button4.updateState(); |
nnguyen45 | 32:e87bb6e83072 | 95 | Thread::wait(200); // wait till thread is done |
aismail1997 | 18:d14bf57f435b | 96 | } |
aismail1997 | 18:d14bf57f435b | 97 | } |
aismail1997 | 18:d14bf57f435b | 98 | |
aismail1997 | 18:d14bf57f435b | 99 | // thread for the custom button |
aismail1997 | 18:d14bf57f435b | 100 | void button5_thread() |
aismail1997 | 18:d14bf57f435b | 101 | { |
aismail1997 | 18:d14bf57f435b | 102 | while(true) { |
aismail1997 | 19:ceac47be2e64 | 103 | state5 = button5.updateState(); |
nnguyen45 | 32:e87bb6e83072 | 104 | Thread::wait(200); // wait till thread is done |
aismail1997 | 18:d14bf57f435b | 105 | } |
aismail1997 | 18:d14bf57f435b | 106 | } |
aismail1997 | 18:d14bf57f435b | 107 | |
aismail1997 | 14:581a3b02f4c3 | 108 | |
aismail1997 | 0:9eda4611081a | 109 | int main() |
aismail1997 | 0:9eda4611081a | 110 | { |
aismail1997 | 6:1aa86ad19af9 | 111 | // SETUP |
aismail1997 | 4:cc181f8f2bd1 | 112 | // pull up the pushbutton to prevent bouncing |
aismail1997 | 16:5c91af9b4e7c | 113 | pb1.mode(PullUp); |
aismail1997 | 16:5c91af9b4e7c | 114 | pb2.mode(PullUp); |
aismail1997 | 18:d14bf57f435b | 115 | pb3.mode(PullUp); |
aismail1997 | 18:d14bf57f435b | 116 | pb4.mode(PullUp); |
aismail1997 | 18:d14bf57f435b | 117 | pb5.mode(PullUp); |
aismail1997 | 18:d14bf57f435b | 118 | pb6.mode(PullUp); |
aismail1997 | 30:79cdf893c8b8 | 119 | wait(.001); |
aismail1997 | 15:7e9308d14faa | 120 | |
aismail1997 | 23:23970cf718ee | 121 | // PARSE INPUT FILE FOR LETTERS AND WORDS |
aismail1997 | 23:23970cf718ee | 122 | char delimiter = ','; |
aismail1997 | 29:b9bd85682db1 | 123 | // TODO: fix the letters |
aismail1997 | 23:23970cf718ee | 124 | string letter[2]; |
aismail1997 | 23:23970cf718ee | 125 | string word[2]; |
aismail1997 | 23:23970cf718ee | 126 | char check; |
aismail1997 | 23:23970cf718ee | 127 | string temp; |
aismail1997 | 23:23970cf718ee | 128 | string tempword = ""; |
aismail1997 | 23:23970cf718ee | 129 | int counter = 0; |
aismail1997 | 23:23970cf718ee | 130 | FILE *fp = fopen("/sd/plan.txt", "r"); //create file |
aismail1997 | 23:23970cf718ee | 131 | if(fp == NULL) { |
aismail1997 | 30:79cdf893c8b8 | 132 | //pc.printf("Could not open file for write\n"); |
aismail1997 | 23:23970cf718ee | 133 | } |
aismail1997 | 23:23970cf718ee | 134 | check = fgetc(fp); //grabs a char from file |
aismail1997 | 23:23970cf718ee | 135 | while(check != '\n') { //while not at the end of line for letters |
aismail1997 | 23:23970cf718ee | 136 | if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored |
aismail1997 | 23:23970cf718ee | 137 | letter[counter] = temp; //write letter |
aismail1997 | 23:23970cf718ee | 138 | counter = counter + 1; //increment counter |
aismail1997 | 23:23970cf718ee | 139 | } else { |
aismail1997 | 23:23970cf718ee | 140 | temp = check; //store letter |
aismail1997 | 23:23970cf718ee | 141 | } |
aismail1997 | 23:23970cf718ee | 142 | check = fgetc(fp); //grabs next char |
aismail1997 | 23:23970cf718ee | 143 | } |
aismail1997 | 23:23970cf718ee | 144 | counter = 0; //reset counter |
aismail1997 | 23:23970cf718ee | 145 | check = fgetc(fp); //grabs next char |
aismail1997 | 23:23970cf718ee | 146 | while(!feof(fp)) { //while not at the end of line for words |
aismail1997 | 23:23970cf718ee | 147 | if(check == delimiter) { //when at the comma at the end of a word |
aismail1997 | 23:23970cf718ee | 148 | word[counter] = tempword; //write word |
aismail1997 | 23:23970cf718ee | 149 | tempword = ""; |
aismail1997 | 23:23970cf718ee | 150 | counter = counter + 1; //increment counter |
aismail1997 | 23:23970cf718ee | 151 | } else { |
aismail1997 | 23:23970cf718ee | 152 | tempword = tempword + check; //concatenate letters to build word |
aismail1997 | 23:23970cf718ee | 153 | } |
aismail1997 | 23:23970cf718ee | 154 | check = fgetc(fp); //grabs next char |
aismail1997 | 23:23970cf718ee | 155 | } |
aismail1997 | 23:23970cf718ee | 156 | fclose(fp); //close file |
aismail1997 | 14:581a3b02f4c3 | 157 | |
nnguyen45 | 33:3090ec93b4aa | 158 | Thread t1(button_thread); |
nnguyen45 | 33:3090ec93b4aa | 159 | Thread t2(button2_thread); |
nnguyen45 | 33:3090ec93b4aa | 160 | Thread t3(button3_thread); |
nnguyen45 | 33:3090ec93b4aa | 161 | Thread t4(button4_thread); |
nnguyen45 | 33:3090ec93b4aa | 162 | Thread t5(button5_thread); |
nnguyen45 | 33:3090ec93b4aa | 163 | //Thread t6(button6_thread); |
nnguyen45 | 33:3090ec93b4aa | 164 | t1.start(button_thread); |
nnguyen45 | 33:3090ec93b4aa | 165 | t2.start(button2_thread); |
nnguyen45 | 33:3090ec93b4aa | 166 | t3.start(button3_thread); |
nnguyen45 | 33:3090ec93b4aa | 167 | t4.start(button4_thread); |
nnguyen45 | 33:3090ec93b4aa | 168 | t5.start(button5_thread); |
nnguyen45 | 33:3090ec93b4aa | 169 | //t6.start(button6_thread); |
aismail1997 | 34:1248dfa0740b | 170 | |
aismail1997 | 41:560ee7866781 | 171 | //char currletter; |
aismail1997 | 23:23970cf718ee | 172 | int lettersize = sizeof(letter)/sizeof(letter[0]); |
aismail1997 | 41:560ee7866781 | 173 | //int type = 0; |
aismail1997 | 34:1248dfa0740b | 174 | |
aismail1997 | 28:3c4ebc4fde0f | 175 | //TEXT-TO-SPEECH LOGIC |
aismail1997 | 41:560ee7866781 | 176 | myTTS.volume(3); //max volume is 18 |
nnguyen45 | 31:e5024aeca3a7 | 177 | myTTS.voice(2); |
aismail1997 | 28:3c4ebc4fde0f | 178 | |
aismail1997 | 41:560ee7866781 | 179 | // SETUP |
aismail1997 | 41:560ee7866781 | 180 | /* buttonarr.setup(); //Reset servos so that buttons are up for typing mode |
aismail1997 | 41:560ee7866781 | 181 | button1.setMode(1); |
aismail1997 | 41:560ee7866781 | 182 | button2.setMode(1); |
aismail1997 | 41:560ee7866781 | 183 | button3.setMode(1); |
aismail1997 | 41:560ee7866781 | 184 | button4.setMode(1); |
aismail1997 | 41:560ee7866781 | 185 | button5.setMode(1); |
aismail1997 | 41:560ee7866781 | 186 | button6.setMode(1); |
aismail1997 | 41:560ee7866781 | 187 | |
aismail1997 | 41:560ee7866781 | 188 | // LETTER CODE |
aismail1997 | 41:560ee7866781 | 189 | // tell how to type letter |
aismail1997 | 41:560ee7866781 | 190 | // wait for input |
aismail1997 | 41:560ee7866781 | 191 | // check if correct letter |
aismail1997 | 41:560ee7866781 | 192 | // feedback |
aismail1997 | 41:560ee7866781 | 193 | // loop |
aismail1997 | 41:560ee7866781 | 194 | |
aismail1997 | 41:560ee7866781 | 195 | for(int i = 0; i < lettersize; i++) { //iterate through the letter array |
aismail1997 | 41:560ee7866781 | 196 | char currletter = letter[i][0]; |
aismail1997 | 41:560ee7866781 | 197 | int* pinsup = buttonarr.pinsUp(currletter); |
aismail1997 | 41:560ee7866781 | 198 | int currpress; |
aismail1997 | 41:560ee7866781 | 199 | int numpinsups = pinsup[0]; // size of array is first element of pinsup |
aismail1997 | 41:560ee7866781 | 200 | string presspin = "STo write the letter "; |
aismail1997 | 41:560ee7866781 | 201 | presspin = presspin + letter[i]; |
aismail1997 | 41:560ee7866781 | 202 | presspin = presspin + ", press buttons"; |
aismail1997 | 41:560ee7866781 | 203 | |
aismail1997 | 41:560ee7866781 | 204 | for (int j = 1; j < numpinsups; j++) { // get what pins to press |
aismail1997 | 41:560ee7866781 | 205 | currpress = pinsup[j]; |
aismail1997 | 41:560ee7866781 | 206 | switch (currpress) { |
aismail1997 | 41:560ee7866781 | 207 | case 1: |
aismail1997 | 41:560ee7866781 | 208 | presspin = presspin + " 1,"; |
aismail1997 | 41:560ee7866781 | 209 | break; |
aismail1997 | 41:560ee7866781 | 210 | case 2: |
aismail1997 | 41:560ee7866781 | 211 | presspin = presspin + " 2,"; |
aismail1997 | 41:560ee7866781 | 212 | break; |
aismail1997 | 41:560ee7866781 | 213 | case 3: |
aismail1997 | 41:560ee7866781 | 214 | presspin = presspin + " 3,"; |
aismail1997 | 41:560ee7866781 | 215 | break; |
aismail1997 | 41:560ee7866781 | 216 | case 4: |
aismail1997 | 41:560ee7866781 | 217 | presspin = presspin + " 4,"; |
aismail1997 | 41:560ee7866781 | 218 | break; |
aismail1997 | 41:560ee7866781 | 219 | case 5: |
aismail1997 | 41:560ee7866781 | 220 | presspin = presspin + " 5,"; |
aismail1997 | 41:560ee7866781 | 221 | break; |
aismail1997 | 41:560ee7866781 | 222 | case 6: |
aismail1997 | 41:560ee7866781 | 223 | presspin = presspin + " 6,"; |
aismail1997 | 41:560ee7866781 | 224 | break; |
aismail1997 | 41:560ee7866781 | 225 | } |
aismail1997 | 41:560ee7866781 | 226 | } |
aismail1997 | 41:560ee7866781 | 227 | myTTS.speakf("%s\r",presspin); |
aismail1997 | 41:560ee7866781 | 228 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
aismail1997 | 41:560ee7866781 | 229 | //wait(2); |
aismail1997 | 41:560ee7866781 | 230 | |
aismail1997 | 41:560ee7866781 | 231 | //WORKS UP TO HERE |
aismail1997 | 41:560ee7866781 | 232 | char* braille; |
aismail1997 | 41:560ee7866781 | 233 | char* oldbraille; |
aismail1997 | 41:560ee7866781 | 234 | |
aismail1997 | 41:560ee7866781 | 235 | // TYPE MODE |
aismail1997 | 41:560ee7866781 | 236 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 41:560ee7866781 | 237 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 41:560ee7866781 | 238 | |
aismail1997 | 41:560ee7866781 | 239 | // wait for input |
aismail1997 | 41:560ee7866781 | 240 | while (strcmp(braille, "111111") == 0) { |
aismail1997 | 41:560ee7866781 | 241 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 41:560ee7866781 | 242 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 41:560ee7866781 | 243 | } |
aismail1997 | 41:560ee7866781 | 244 | |
aismail1997 | 41:560ee7866781 | 245 | // while buttons have not been released |
aismail1997 | 41:560ee7866781 | 246 | int oldsum = 0; |
aismail1997 | 41:560ee7866781 | 247 | int sum = 0; |
aismail1997 | 41:560ee7866781 | 248 | while ((strcmp(braille, "111111") != 0) && (oldsum <= sum)) { |
aismail1997 | 41:560ee7866781 | 249 | oldbraille = braille; |
aismail1997 | 41:560ee7866781 | 250 | oldsum = sum; |
aismail1997 | 41:560ee7866781 | 251 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 41:560ee7866781 | 252 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 41:560ee7866781 | 253 | sum = button1.getPress() + button2.getPress() + button3.getPress() + button4.getPress() |
aismail1997 | 41:560ee7866781 | 254 | + button5.getPress() + button6.getPress(); |
aismail1997 | 41:560ee7866781 | 255 | } |
aismail1997 | 41:560ee7866781 | 256 | braille = oldbraille; |
aismail1997 | 41:560ee7866781 | 257 | |
aismail1997 | 41:560ee7866781 | 258 | int currwrong; |
aismail1997 | 41:560ee7866781 | 259 | string wrongpin; |
aismail1997 | 41:560ee7866781 | 260 | // check result |
aismail1997 | 41:560ee7866781 | 261 | int* wrongpins = buttonarr.wrongPins(braille, currletter); |
aismail1997 | 41:560ee7866781 | 262 | int test = 1; |
aismail1997 | 41:560ee7866781 | 263 | while(test == 1) { |
aismail1997 | 41:560ee7866781 | 264 | wrongpin = "SYour answer is incorrect. Buttons"; |
aismail1997 | 41:560ee7866781 | 265 | for (int j = 1; j < wrongpins[0]; j++) { // get what pins are wrong |
aismail1997 | 41:560ee7866781 | 266 | currwrong = wrongpins[j]; |
aismail1997 | 41:560ee7866781 | 267 | switch (currwrong) { |
aismail1997 | 41:560ee7866781 | 268 | case 1: |
aismail1997 | 41:560ee7866781 | 269 | wrongpin = wrongpin + " 1,"; |
aismail1997 | 41:560ee7866781 | 270 | break; |
aismail1997 | 41:560ee7866781 | 271 | case 2: |
aismail1997 | 41:560ee7866781 | 272 | wrongpin = wrongpin + " 2,"; |
aismail1997 | 41:560ee7866781 | 273 | break; |
aismail1997 | 41:560ee7866781 | 274 | case 3: |
aismail1997 | 41:560ee7866781 | 275 | wrongpin = wrongpin + " 3,"; |
aismail1997 | 41:560ee7866781 | 276 | break; |
aismail1997 | 41:560ee7866781 | 277 | case 4: |
aismail1997 | 41:560ee7866781 | 278 | wrongpin = wrongpin + " 4,"; |
aismail1997 | 41:560ee7866781 | 279 | break; |
aismail1997 | 41:560ee7866781 | 280 | case 5: |
aismail1997 | 41:560ee7866781 | 281 | wrongpin = wrongpin + " 5,"; |
aismail1997 | 41:560ee7866781 | 282 | break; |
aismail1997 | 41:560ee7866781 | 283 | case 6: |
aismail1997 | 41:560ee7866781 | 284 | wrongpin = wrongpin + " 6,"; |
aismail1997 | 41:560ee7866781 | 285 | break; |
aismail1997 | 41:560ee7866781 | 286 | } |
aismail1997 | 41:560ee7866781 | 287 | } |
aismail1997 | 41:560ee7866781 | 288 | if (wrongpins[0] > 1) { |
aismail1997 | 41:560ee7866781 | 289 | wrongpin = wrongpin + " are wrong. Please try again."; |
aismail1997 | 41:560ee7866781 | 290 | myTTS.speakf("%s\r",wrongpin); |
aismail1997 | 41:560ee7866781 | 291 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
aismail1997 | 41:560ee7866781 | 292 | |
aismail1997 | 41:560ee7866781 | 293 | //UPDATE THE PINS THAT ARE WRONG BY CHECKING AGAIN BELOW |
aismail1997 | 41:560ee7866781 | 294 | |
aismail1997 | 41:560ee7866781 | 295 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 41:560ee7866781 | 296 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 41:560ee7866781 | 297 | |
aismail1997 | 41:560ee7866781 | 298 | // wait for input |
aismail1997 | 41:560ee7866781 | 299 | while (strcmp(braille, "111111") == 0) { |
aismail1997 | 41:560ee7866781 | 300 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 41:560ee7866781 | 301 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 41:560ee7866781 | 302 | } |
aismail1997 | 41:560ee7866781 | 303 | |
aismail1997 | 41:560ee7866781 | 304 | // while buttons have not been released |
aismail1997 | 41:560ee7866781 | 305 | int oldsum = 0; |
aismail1997 | 41:560ee7866781 | 306 | int sum = 0; |
aismail1997 | 41:560ee7866781 | 307 | while ((strcmp(braille, "111111") != 0) && (oldsum <= sum)) { |
aismail1997 | 41:560ee7866781 | 308 | oldbraille = braille; |
aismail1997 | 41:560ee7866781 | 309 | oldsum = sum; |
aismail1997 | 41:560ee7866781 | 310 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 41:560ee7866781 | 311 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 41:560ee7866781 | 312 | sum = button1.getPress() + button2.getPress() + button3.getPress() + button4.getPress() |
aismail1997 | 41:560ee7866781 | 313 | + button5.getPress() + button6.getPress(); |
aismail1997 | 41:560ee7866781 | 314 | } |
aismail1997 | 41:560ee7866781 | 315 | |
aismail1997 | 41:560ee7866781 | 316 | // check result |
aismail1997 | 41:560ee7866781 | 317 | wrongpins = buttonarr.wrongPins(braille, currletter); |
aismail1997 | 41:560ee7866781 | 318 | } else { |
aismail1997 | 41:560ee7866781 | 319 | test = 0; |
aismail1997 | 41:560ee7866781 | 320 | myTTS.speakf("SGood job!\r"); |
aismail1997 | 41:560ee7866781 | 321 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
aismail1997 | 41:560ee7866781 | 322 | } |
aismail1997 | 41:560ee7866781 | 323 | } |
aismail1997 | 41:560ee7866781 | 324 | |
aismail1997 | 41:560ee7866781 | 325 | }*/ |
aismail1997 | 41:560ee7866781 | 326 | |
aismail1997 | 37:d873136dfb12 | 327 | // WORD CODE |
aismail1997 | 37:d873136dfb12 | 328 | |
aismail1997 | 37:d873136dfb12 | 329 | // WORD COUNTER |
aismail1997 | 37:d873136dfb12 | 330 | // go through each word |
aismail1997 | 37:d873136dfb12 | 331 | // go through each letter in the word |
aismail1997 | 37:d873136dfb12 | 332 | // get user input |
aismail1997 | 37:d873136dfb12 | 333 | // when buttons reset - save previous letter |
aismail1997 | 37:d873136dfb12 | 334 | // loop until submit button is pressed |
aismail1997 | 37:d873136dfb12 | 335 | // compare words |
aismail1997 | 37:d873136dfb12 | 336 | // check what letters were wrong |
aismail1997 | 37:d873136dfb12 | 337 | // give wrong letters - correct spelling is... |
aismail1997 | 37:d873136dfb12 | 338 | |
nnguyen45 | 38:68f7f54b723b | 339 | buttonarr.setup(); //Reset servos so that buttons are up for typing mode |
aismail1997 | 39:8cc80f0b4398 | 340 | |
aismail1997 | 39:8cc80f0b4398 | 341 | button1.setMode(1); |
aismail1997 | 39:8cc80f0b4398 | 342 | button2.setMode(1); |
aismail1997 | 39:8cc80f0b4398 | 343 | button3.setMode(1); |
aismail1997 | 39:8cc80f0b4398 | 344 | button4.setMode(1); |
aismail1997 | 39:8cc80f0b4398 | 345 | button5.setMode(1); |
aismail1997 | 39:8cc80f0b4398 | 346 | button6.setMode(1); |
aismail1997 | 39:8cc80f0b4398 | 347 | |
aismail1997 | 37:d873136dfb12 | 348 | string currword; |
aismail1997 | 37:d873136dfb12 | 349 | int wordsize = sizeof(word)/sizeof(word[0]); |
aismail1997 | 41:560ee7866781 | 350 | |
nnguyen45 | 38:68f7f54b723b | 351 | //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 |
nnguyen45 | 38:68f7f54b723b | 352 | 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 |
aismail1997 | 37:d873136dfb12 | 353 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
aismail1997 | 39:8cc80f0b4398 | 354 | |
aismail1997 | 39:8cc80f0b4398 | 355 | // loop through each of the words |
aismail1997 | 37:d873136dfb12 | 356 | for(int i = 0; i < wordsize; i++) { //iterate through the word array |
aismail1997 | 37:d873136dfb12 | 357 | currword = word[i]; |
aismail1997 | 40:85be3490d3a7 | 358 | char currword1[3]; |
aismail1997 | 41:560ee7866781 | 359 | |
aismail1997 | 37:d873136dfb12 | 360 | string presspin = "To type the word "; |
aismail1997 | 37:d873136dfb12 | 361 | presspin = presspin + word[i]; |
aismail1997 | 37:d873136dfb12 | 362 | presspin = presspin + ", type letters "; |
aismail1997 | 37:d873136dfb12 | 363 | for (int j = 0; j < currword.length(); j++) { |
aismail1997 | 37:d873136dfb12 | 364 | presspin = presspin + ", "+ currword[j]; |
aismail1997 | 40:85be3490d3a7 | 365 | currword1[j] = currword[j]; |
aismail1997 | 37:d873136dfb12 | 366 | } |
aismail1997 | 39:8cc80f0b4398 | 367 | |
aismail1997 | 39:8cc80f0b4398 | 368 | myTTS.speakf("S%s\r", presspin); |
aismail1997 | 39:8cc80f0b4398 | 369 | myTTS.ready(); |
aismail1997 | 39:8cc80f0b4398 | 370 | |
aismail1997 | 39:8cc80f0b4398 | 371 | // loop through each of the letters |
aismail1997 | 39:8cc80f0b4398 | 372 | int incorrect = 1; |
aismail1997 | 39:8cc80f0b4398 | 373 | char userinput; |
aismail1997 | 37:d873136dfb12 | 374 | |
aismail1997 | 39:8cc80f0b4398 | 375 | // while(!submit) |
aismail1997 | 39:8cc80f0b4398 | 376 | while (incorrect == 1) { |
aismail1997 | 39:8cc80f0b4398 | 377 | |
aismail1997 | 40:85be3490d3a7 | 378 | char wordinput[3]; |
aismail1997 | 39:8cc80f0b4398 | 379 | // replace for loop with submit |
aismail1997 | 39:8cc80f0b4398 | 380 | // while (!submit) { |
aismail1997 | 39:8cc80f0b4398 | 381 | |
aismail1997 | 40:85be3490d3a7 | 382 | for (int j = 0; j < 3; j++) { |
aismail1997 | 39:8cc80f0b4398 | 383 | // check if all buttons were pressed |
aismail1997 | 37:d873136dfb12 | 384 | |
aismail1997 | 39:8cc80f0b4398 | 385 | char* braille; |
aismail1997 | 39:8cc80f0b4398 | 386 | char* oldbraille; |
aismail1997 | 37:d873136dfb12 | 387 | |
aismail1997 | 39:8cc80f0b4398 | 388 | wait(1); |
aismail1997 | 39:8cc80f0b4398 | 389 | |
aismail1997 | 39:8cc80f0b4398 | 390 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 39:8cc80f0b4398 | 391 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 39:8cc80f0b4398 | 392 | //pc.printf("test %s ", braille); |
aismail1997 | 37:d873136dfb12 | 393 | |
aismail1997 | 39:8cc80f0b4398 | 394 | // wait for input |
aismail1997 | 39:8cc80f0b4398 | 395 | while (strcmp(braille, "111111") == 0) { |
aismail1997 | 39:8cc80f0b4398 | 396 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 39:8cc80f0b4398 | 397 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 39:8cc80f0b4398 | 398 | } |
aismail1997 | 19:ceac47be2e64 | 399 | |
aismail1997 | 39:8cc80f0b4398 | 400 | // while buttons have not been released |
aismail1997 | 39:8cc80f0b4398 | 401 | int oldsum = 0; |
aismail1997 | 39:8cc80f0b4398 | 402 | int sum = 0; |
aismail1997 | 39:8cc80f0b4398 | 403 | while ((strcmp(braille, "111111") != 0) && (oldsum <= sum)) { |
aismail1997 | 39:8cc80f0b4398 | 404 | oldbraille = braille; |
aismail1997 | 39:8cc80f0b4398 | 405 | oldsum = sum; |
aismail1997 | 39:8cc80f0b4398 | 406 | sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(), |
aismail1997 | 39:8cc80f0b4398 | 407 | !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress()); |
aismail1997 | 39:8cc80f0b4398 | 408 | sum = button1.getPress() + button2.getPress() + button3.getPress() + button4.getPress() |
aismail1997 | 39:8cc80f0b4398 | 409 | + button5.getPress() + button6.getPress(); |
aismail1997 | 37:d873136dfb12 | 410 | } |
aismail1997 | 22:6931917c70cd | 411 | |
aismail1997 | 39:8cc80f0b4398 | 412 | // at the end of this, oldbraille contains the letter representation |
aismail1997 | 39:8cc80f0b4398 | 413 | //pc.printf("%s ", oldbraille); |
aismail1997 | 39:8cc80f0b4398 | 414 | userinput = buttonarr.checkVal(oldbraille); |
aismail1997 | 40:85be3490d3a7 | 415 | //pc.printf("%c ", userinput); |
aismail1997 | 39:8cc80f0b4398 | 416 | wordinput[j] = userinput; |
aismail1997 | 39:8cc80f0b4398 | 417 | } |
aismail1997 | 39:8cc80f0b4398 | 418 | |
aismail1997 | 39:8cc80f0b4398 | 419 | // check result of words |
aismail1997 | 39:8cc80f0b4398 | 420 | incorrect = 0; |
aismail1997 | 40:85be3490d3a7 | 421 | for (int k = 0; k < 3; k++) { |
aismail1997 | 40:85be3490d3a7 | 422 | //pc.printf("%c %c\n", currword[k], wordinput[k]); |
aismail1997 | 40:85be3490d3a7 | 423 | if (currword1[k] != wordinput[k]) { // if any letter doesn't match |
aismail1997 | 39:8cc80f0b4398 | 424 | incorrect = 1; // spelling is wrong |
aismail1997 | 37:d873136dfb12 | 425 | } |
aismail1997 | 37:d873136dfb12 | 426 | } |
aismail1997 | 37:d873136dfb12 | 427 | |
aismail1997 | 39:8cc80f0b4398 | 428 | if (incorrect == 1) { |
aismail1997 | 39:8cc80f0b4398 | 429 | myTTS.speakf("SPlease try again! %s\r", presspin); |
aismail1997 | 39:8cc80f0b4398 | 430 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
aismail1997 | 39:8cc80f0b4398 | 431 | //wait(2); |
aismail1997 | 39:8cc80f0b4398 | 432 | //incorrect = 1; |
aismail1997 | 39:8cc80f0b4398 | 433 | } else { |
aismail1997 | 39:8cc80f0b4398 | 434 | //wait(1); |
aismail1997 | 39:8cc80f0b4398 | 435 | myTTS.speakf("SGood job!\r"); |
aismail1997 | 39:8cc80f0b4398 | 436 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
aismail1997 | 39:8cc80f0b4398 | 437 | } |
nnguyen45 | 38:68f7f54b723b | 438 | } |
aismail1997 | 39:8cc80f0b4398 | 439 | } |
aismail1997 | 37:d873136dfb12 | 440 | |
aismail1997 | 37:d873136dfb12 | 441 | // MAIN THREAD |
aismail1997 | 37:d873136dfb12 | 442 | while(true) { |
aismail1997 | 22:6931917c70cd | 443 | |
aismail1997 | 14:581a3b02f4c3 | 444 | Thread::wait(500); // wait till thread is done |
aismail1997 | 0:9eda4611081a | 445 | } |
aismail1997 | 0:9eda4611081a | 446 | } |