Working read code with mode button
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_senior_design_Testnew by
main.cpp@27:0ed2a9cad0e1, 2017-11-15 (annotated)
- Committer:
- nnguyen45
- Date:
- Wed Nov 15 16:09:16 2017 +0000
- Revision:
- 27:0ed2a9cad0e1
- Parent:
- 26:4b2940eec275
working intro and beginning of text-to-speech
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aismail1997 | 2:9eda4611081a | 1 | #include "mbed.h" |
aismail1997 | 8:1aa86ad19af9 | 2 | #include "rtos.h" |
aismail1997 | 11:418a4437a693 | 3 | #include "wave_player.h" |
aismail1997 | 11:418a4437a693 | 4 | #include "SDFileSystem.h" |
aismail1997 | 12:21268d8bf979 | 5 | #include "button.h" |
aismail1997 | 21:ceac47be2e64 | 6 | #include "buttonArray.h" |
aismail1997 | 25:23970cf718ee | 7 | #include <string> |
aismail1997 | 25:23970cf718ee | 8 | #include <iostream> |
nnguyen45 | 26:4b2940eec275 | 9 | #include "emic2.h" |
nnguyen45 | 27:0ed2a9cad0e1 | 10 | #include <stdio.h> |
aismail1997 | 25:23970cf718ee | 11 | |
aismail1997 | 25:23970cf718ee | 12 | using namespace std; |
aismail1997 | 5:9ed43e974156 | 13 | |
aismail1997 | 15:b80dde24e9bc | 14 | // DEFINE I/O |
aismail1997 | 2:9eda4611081a | 15 | PwmOut myservo(p21); |
aismail1997 | 2:9eda4611081a | 16 | DigitalIn pb1 (p20); |
aismail1997 | 16:581a3b02f4c3 | 17 | PwmOut myservo2(p22); |
aismail1997 | 16:581a3b02f4c3 | 18 | DigitalIn pb2 (p19); |
aismail1997 | 20:d14bf57f435b | 19 | PwmOut myservo3(p23); |
aismail1997 | 20:d14bf57f435b | 20 | DigitalIn pb3 (p18); |
aismail1997 | 20:d14bf57f435b | 21 | PwmOut myservo4(p24); |
aismail1997 | 20:d14bf57f435b | 22 | DigitalIn pb4 (p17); |
aismail1997 | 20:d14bf57f435b | 23 | PwmOut myservo5(p25); |
aismail1997 | 20:d14bf57f435b | 24 | DigitalIn pb5 (p16); |
aismail1997 | 20:d14bf57f435b | 25 | PwmOut myservo6(p26); |
aismail1997 | 20:d14bf57f435b | 26 | DigitalIn pb6 (p15); |
aismail1997 | 20:d14bf57f435b | 27 | |
aismail1997 | 20:d14bf57f435b | 28 | //DigitalOut led1(LED1); |
aismail1997 | 20:d14bf57f435b | 29 | //DigitalOut led3(LED3); |
aismail1997 | 24:6931917c70cd | 30 | //DigitalOut led4(LED4); |
aismail1997 | 16:581a3b02f4c3 | 31 | |
aismail1997 | 24:6931917c70cd | 32 | DigitalIn linpot(p9); |
aismail1997 | 25:23970cf718ee | 33 | Serial pc(USBTX, USBRX); |
aismail1997 | 25:23970cf718ee | 34 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
nnguyen45 | 26:4b2940eec275 | 35 | emic2 myTTS(p28, p27); //serial RX,TX pins to emic |
nnguyen45 | 26:4b2940eec275 | 36 | |
aismail1997 | 16:581a3b02f4c3 | 37 | //AnalogOut DACout(p26); |
aismail1997 | 16:581a3b02f4c3 | 38 | //wave_player waver(&DACout); |
aismail1997 | 23:c5df903f068a | 39 | //button button1(myservo, pb1, linpot); |
aismail1997 | 23:c5df903f068a | 40 | button button1(myservo, pb1, 1); |
aismail1997 | 23:c5df903f068a | 41 | button button2(myservo2, pb2, 2); |
aismail1997 | 23:c5df903f068a | 42 | button button3(myservo3, pb3, 3); |
aismail1997 | 23:c5df903f068a | 43 | button button4(myservo4, pb4, 4); |
aismail1997 | 23:c5df903f068a | 44 | button button5(myservo5, pb5, 5); |
aismail1997 | 23:c5df903f068a | 45 | button button6(myservo6, pb6, 6); |
aismail1997 | 6:cc181f8f2bd1 | 46 | |
aismail1997 | 21:ceac47be2e64 | 47 | buttonArray buttonarr(button1, button2, button3, button4, button5, button6); |
aismail1997 | 21:ceac47be2e64 | 48 | |
aismail1997 | 15:b80dde24e9bc | 49 | // INITIALIZE VARIABLES |
aismail1997 | 15:b80dde24e9bc | 50 | // add mode, reset buttons |
aismail1997 | 11:418a4437a693 | 51 | int start = 0; |
aismail1997 | 11:418a4437a693 | 52 | int submit = 0; |
aismail1997 | 20:d14bf57f435b | 53 | // Buttons begins in up state |
aismail1997 | 19:08c575082052 | 54 | int state = 0; |
aismail1997 | 20:d14bf57f435b | 55 | int state2 = 0; |
aismail1997 | 20:d14bf57f435b | 56 | int state3 = 0; |
aismail1997 | 20:d14bf57f435b | 57 | int state4 = 0; |
aismail1997 | 20:d14bf57f435b | 58 | int state5 = 0; |
aismail1997 | 20:d14bf57f435b | 59 | int state6 = 0; |
aismail1997 | 16:581a3b02f4c3 | 60 | int count = 0; |
aismail1997 | 8:1aa86ad19af9 | 61 | |
aismail1997 | 8:1aa86ad19af9 | 62 | // THREADS |
aismail1997 | 15:b80dde24e9bc | 63 | |
aismail1997 | 8:1aa86ad19af9 | 64 | void button_thread() |
aismail1997 | 6:cc181f8f2bd1 | 65 | { |
aismail1997 | 16:581a3b02f4c3 | 66 | while(true) { |
aismail1997 | 21:ceac47be2e64 | 67 | state = button1.updateState(); |
aismail1997 | 23:c5df903f068a | 68 | //led4 = button1.getLp(); |
aismail1997 | 21:ceac47be2e64 | 69 | Thread::wait(100); // wait till thread is done |
aismail1997 | 12:21268d8bf979 | 70 | } |
aismail1997 | 16:581a3b02f4c3 | 71 | } |
aismail1997 | 16:581a3b02f4c3 | 72 | |
aismail1997 | 16:581a3b02f4c3 | 73 | void button2_thread() |
aismail1997 | 16:581a3b02f4c3 | 74 | { |
aismail1997 | 16:581a3b02f4c3 | 75 | while(true) { |
aismail1997 | 21:ceac47be2e64 | 76 | state2 = button2.updateState(); |
aismail1997 | 16:581a3b02f4c3 | 77 | Thread::wait(100); // wait till thread is done |
aismail1997 | 12:21268d8bf979 | 78 | } |
aismail1997 | 6:cc181f8f2bd1 | 79 | } |
aismail1997 | 6:cc181f8f2bd1 | 80 | |
aismail1997 | 20:d14bf57f435b | 81 | // thread for the custom button |
aismail1997 | 20:d14bf57f435b | 82 | void button3_thread() |
aismail1997 | 20:d14bf57f435b | 83 | { |
aismail1997 | 20:d14bf57f435b | 84 | while(true) { |
aismail1997 | 21:ceac47be2e64 | 85 | state3 = button3.updateState(); |
aismail1997 | 21:ceac47be2e64 | 86 | Thread::wait(100); // wait till thread is done |
aismail1997 | 20:d14bf57f435b | 87 | } |
aismail1997 | 20:d14bf57f435b | 88 | } |
aismail1997 | 20:d14bf57f435b | 89 | |
aismail1997 | 20:d14bf57f435b | 90 | // thread for the custom button |
aismail1997 | 20:d14bf57f435b | 91 | void button4_thread() |
aismail1997 | 20:d14bf57f435b | 92 | { |
aismail1997 | 20:d14bf57f435b | 93 | while(true) { |
aismail1997 | 21:ceac47be2e64 | 94 | state4 = button4.updateState(); |
aismail1997 | 21:ceac47be2e64 | 95 | Thread::wait(100); // wait till thread is done |
aismail1997 | 20:d14bf57f435b | 96 | } |
aismail1997 | 20:d14bf57f435b | 97 | } |
aismail1997 | 20:d14bf57f435b | 98 | |
aismail1997 | 20:d14bf57f435b | 99 | // thread for the custom button |
aismail1997 | 20:d14bf57f435b | 100 | void button5_thread() |
aismail1997 | 20:d14bf57f435b | 101 | { |
aismail1997 | 20:d14bf57f435b | 102 | while(true) { |
aismail1997 | 21:ceac47be2e64 | 103 | state5 = button5.updateState(); |
aismail1997 | 21:ceac47be2e64 | 104 | Thread::wait(100); // wait till thread is done |
aismail1997 | 20:d14bf57f435b | 105 | } |
aismail1997 | 20:d14bf57f435b | 106 | } |
aismail1997 | 20:d14bf57f435b | 107 | |
aismail1997 | 20:d14bf57f435b | 108 | // thread for the custom button |
aismail1997 | 20:d14bf57f435b | 109 | void button6_thread() |
aismail1997 | 20:d14bf57f435b | 110 | { |
aismail1997 | 20:d14bf57f435b | 111 | while(true) { |
aismail1997 | 21:ceac47be2e64 | 112 | state6 = button6.updateState(); |
aismail1997 | 21:ceac47be2e64 | 113 | Thread::wait(100); // wait till thread is done |
aismail1997 | 20:d14bf57f435b | 114 | } |
aismail1997 | 20:d14bf57f435b | 115 | } |
aismail1997 | 20:d14bf57f435b | 116 | |
aismail1997 | 8:1aa86ad19af9 | 117 | void submit_thread() |
aismail1997 | 6:cc181f8f2bd1 | 118 | { |
aismail1997 | 15:b80dde24e9bc | 119 | Thread::wait(500); // wait till thread is done |
aismail1997 | 6:cc181f8f2bd1 | 120 | } |
aismail1997 | 6:cc181f8f2bd1 | 121 | |
aismail1997 | 8:1aa86ad19af9 | 122 | void start_thread() |
aismail1997 | 6:cc181f8f2bd1 | 123 | { |
aismail1997 | 8:1aa86ad19af9 | 124 | // read pb_start |
aismail1997 | 8:1aa86ad19af9 | 125 | // if 1 |
aismail1997 | 16:581a3b02f4c3 | 126 | start = 1; |
aismail1997 | 16:581a3b02f4c3 | 127 | //pc.printf("start %d ", start); |
aismail1997 | 8:1aa86ad19af9 | 128 | // else 0 |
aismail1997 | 15:b80dde24e9bc | 129 | Thread::wait(500); // wait till thread is done |
aismail1997 | 6:cc181f8f2bd1 | 130 | } |
aismail1997 | 2:9eda4611081a | 131 | |
aismail1997 | 16:581a3b02f4c3 | 132 | |
aismail1997 | 2:9eda4611081a | 133 | int main() |
aismail1997 | 2:9eda4611081a | 134 | { |
aismail1997 | 25:23970cf718ee | 135 | /* |
aismail1997 | 8:1aa86ad19af9 | 136 | // SETUP |
aismail1997 | 6:cc181f8f2bd1 | 137 | // pull up the pushbutton to prevent bouncing |
aismail1997 | 18:5c91af9b4e7c | 138 | pb1.mode(PullUp); |
aismail1997 | 18:5c91af9b4e7c | 139 | pb2.mode(PullUp); |
aismail1997 | 20:d14bf57f435b | 140 | pb3.mode(PullUp); |
aismail1997 | 20:d14bf57f435b | 141 | pb4.mode(PullUp); |
aismail1997 | 20:d14bf57f435b | 142 | pb5.mode(PullUp); |
aismail1997 | 20:d14bf57f435b | 143 | pb6.mode(PullUp); |
aismail1997 | 18:5c91af9b4e7c | 144 | wait(.001); |
aismail1997 | 17:7e9308d14faa | 145 | |
aismail1997 | 24:6931917c70cd | 146 | // servos begin at 30 degrees |
aismail1997 | 12:21268d8bf979 | 147 | // replace with a button setup function |
aismail1997 | 2:9eda4611081a | 148 | for(int i=0; i<=3; i++) { |
aismail1997 | 2:9eda4611081a | 149 | myservo = i/100.0; |
aismail1997 | 2:9eda4611081a | 150 | wait(0.01); |
aismail1997 | 2:9eda4611081a | 151 | } |
aismail1997 | 16:581a3b02f4c3 | 152 | for(int i=0; i<=3; i++) { |
aismail1997 | 16:581a3b02f4c3 | 153 | myservo2 = i/100.0; |
aismail1997 | 16:581a3b02f4c3 | 154 | wait(0.01); |
aismail1997 | 16:581a3b02f4c3 | 155 | } |
aismail1997 | 21:ceac47be2e64 | 156 | |
aismail1997 | 20:d14bf57f435b | 157 | for(int i=0; i<=3; i++) { |
aismail1997 | 20:d14bf57f435b | 158 | myservo3 = i/100.0; |
aismail1997 | 20:d14bf57f435b | 159 | wait(0.01); |
aismail1997 | 20:d14bf57f435b | 160 | } |
aismail1997 | 21:ceac47be2e64 | 161 | |
aismail1997 | 20:d14bf57f435b | 162 | for(int i=0; i<=3; i++) { |
aismail1997 | 20:d14bf57f435b | 163 | myservo4 = i/100.0; |
aismail1997 | 20:d14bf57f435b | 164 | wait(0.01); |
aismail1997 | 20:d14bf57f435b | 165 | } |
aismail1997 | 21:ceac47be2e64 | 166 | |
aismail1997 | 20:d14bf57f435b | 167 | for(int i=0; i<=3; i++) { |
aismail1997 | 20:d14bf57f435b | 168 | myservo5 = i/100.0; |
aismail1997 | 20:d14bf57f435b | 169 | wait(0.01); |
aismail1997 | 20:d14bf57f435b | 170 | } |
aismail1997 | 6:cc181f8f2bd1 | 171 | |
aismail1997 | 20:d14bf57f435b | 172 | for(int i=0; i<=3; i++) { |
aismail1997 | 20:d14bf57f435b | 173 | myservo6 = i/100.0; |
aismail1997 | 20:d14bf57f435b | 174 | wait(0.01); |
aismail1997 | 25:23970cf718ee | 175 | }*/ |
aismail1997 | 21:ceac47be2e64 | 176 | |
aismail1997 | 20:d14bf57f435b | 177 | //led1 = 1; |
aismail1997 | 18:5c91af9b4e7c | 178 | //led2 = 1; |
aismail1997 | 25:23970cf718ee | 179 | /*Thread t1(button_thread); |
aismail1997 | 20:d14bf57f435b | 180 | Thread t2(button2_thread); |
aismail1997 | 20:d14bf57f435b | 181 | Thread t3(button3_thread); |
aismail1997 | 20:d14bf57f435b | 182 | Thread t4(button4_thread); |
aismail1997 | 20:d14bf57f435b | 183 | Thread t5(button5_thread); |
aismail1997 | 20:d14bf57f435b | 184 | Thread t6(button6_thread); |
aismail1997 | 20:d14bf57f435b | 185 | t1.start(button_thread); |
aismail1997 | 20:d14bf57f435b | 186 | t2.start(button2_thread); |
aismail1997 | 20:d14bf57f435b | 187 | t3.start(button3_thread); |
aismail1997 | 20:d14bf57f435b | 188 | t4.start(button4_thread); |
aismail1997 | 20:d14bf57f435b | 189 | t5.start(button5_thread); |
aismail1997 | 25:23970cf718ee | 190 | t6.start(button6_thread);*/ |
aismail1997 | 25:23970cf718ee | 191 | |
aismail1997 | 25:23970cf718ee | 192 | // PARSE INPUT FILE FOR LETTERS AND WORDS |
aismail1997 | 25:23970cf718ee | 193 | char delimiter = ','; |
aismail1997 | 25:23970cf718ee | 194 | string letter[2]; |
aismail1997 | 25:23970cf718ee | 195 | string word[2]; |
aismail1997 | 25:23970cf718ee | 196 | char check; |
aismail1997 | 25:23970cf718ee | 197 | string temp; |
aismail1997 | 25:23970cf718ee | 198 | string tempword = ""; |
aismail1997 | 25:23970cf718ee | 199 | int counter = 0; |
aismail1997 | 25:23970cf718ee | 200 | FILE *fp = fopen("/sd/plan.txt", "r"); //create file |
aismail1997 | 25:23970cf718ee | 201 | if(fp == NULL) { |
aismail1997 | 25:23970cf718ee | 202 | pc.printf("Could not open file for write\n"); |
aismail1997 | 25:23970cf718ee | 203 | } |
aismail1997 | 25:23970cf718ee | 204 | check = fgetc(fp); //grabs a char from file |
aismail1997 | 25:23970cf718ee | 205 | while(check != '\n') { //while not at the end of line for letters |
aismail1997 | 25:23970cf718ee | 206 | if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored |
aismail1997 | 25:23970cf718ee | 207 | letter[counter] = temp; //write letter |
aismail1997 | 25:23970cf718ee | 208 | pc.printf("Letter: %s \n", letter[counter]); |
aismail1997 | 25:23970cf718ee | 209 | counter = counter + 1; //increment counter |
aismail1997 | 25:23970cf718ee | 210 | } else { |
aismail1997 | 25:23970cf718ee | 211 | temp = check; //store letter |
aismail1997 | 25:23970cf718ee | 212 | } |
aismail1997 | 25:23970cf718ee | 213 | check = fgetc(fp); //grabs next char |
aismail1997 | 25:23970cf718ee | 214 | } |
aismail1997 | 25:23970cf718ee | 215 | counter = 0; //reset counter |
aismail1997 | 25:23970cf718ee | 216 | check = fgetc(fp); //grabs next char |
aismail1997 | 25:23970cf718ee | 217 | while(!feof(fp)) { //while not at the end of line for words |
aismail1997 | 25:23970cf718ee | 218 | if(check == delimiter) { //when at the comma at the end of a word |
aismail1997 | 25:23970cf718ee | 219 | word[counter] = tempword; //write word |
aismail1997 | 25:23970cf718ee | 220 | pc.printf("Word: %s \n", word[counter]); |
aismail1997 | 25:23970cf718ee | 221 | tempword = ""; |
aismail1997 | 25:23970cf718ee | 222 | counter = counter + 1; //increment counter |
aismail1997 | 25:23970cf718ee | 223 | } else { |
aismail1997 | 25:23970cf718ee | 224 | tempword = tempword + check; //concatenate letters to build word |
aismail1997 | 25:23970cf718ee | 225 | } |
aismail1997 | 25:23970cf718ee | 226 | check = fgetc(fp); //grabs next char |
aismail1997 | 25:23970cf718ee | 227 | } |
aismail1997 | 25:23970cf718ee | 228 | fclose(fp); //close file |
aismail1997 | 16:581a3b02f4c3 | 229 | |
aismail1997 | 16:581a3b02f4c3 | 230 | // start threads for reset, mode, start |
aismail1997 | 16:581a3b02f4c3 | 231 | //Thread t1(start_thread); |
aismail1997 | 16:581a3b02f4c3 | 232 | //pc.printf("start thread"); |
aismail1997 | 16:581a3b02f4c3 | 233 | //Thread t2(submit_thread); |
aismail1997 | 16:581a3b02f4c3 | 234 | // setup SDcard and Speaker |
aismail1997 | 16:581a3b02f4c3 | 235 | |
aismail1997 | 16:581a3b02f4c3 | 236 | // when started |
aismail1997 | 16:581a3b02f4c3 | 237 | //while (start == 0){} |
aismail1997 | 16:581a3b02f4c3 | 238 | //Thread t3(button_thread); |
aismail1997 | 16:581a3b02f4c3 | 239 | //pc.printf("button thread"); |
aismail1997 | 16:581a3b02f4c3 | 240 | //Thread t4(button2_thread); |
aismail1997 | 16:581a3b02f4c3 | 241 | //pc.printf("button2 thread"); |
aismail1997 | 16:581a3b02f4c3 | 242 | |
aismail1997 | 16:581a3b02f4c3 | 243 | //Thread t3(submit_thread); |
aismail1997 | 16:581a3b02f4c3 | 244 | |
aismail1997 | 16:581a3b02f4c3 | 245 | // when submitted |
aismail1997 | 16:581a3b02f4c3 | 246 | //while (submit == 0) {} |
aismail1997 | 16:581a3b02f4c3 | 247 | |
aismail1997 | 16:581a3b02f4c3 | 248 | // start button threads and submit thread |
aismail1997 | 16:581a3b02f4c3 | 249 | // if submit close button threads and submit thread |
aismail1997 | 16:581a3b02f4c3 | 250 | // check result |
aismail1997 | 16:581a3b02f4c3 | 251 | // play results on speaker |
aismail1997 | 16:581a3b02f4c3 | 252 | // save results |
aismail1997 | 25:23970cf718ee | 253 | char currletter; |
aismail1997 | 25:23970cf718ee | 254 | int lettersize = sizeof(letter)/sizeof(letter[0]); |
aismail1997 | 25:23970cf718ee | 255 | for (int i = 0; i < lettersize; i++) { |
aismail1997 | 25:23970cf718ee | 256 | currletter = letter[i][0]; |
aismail1997 | 25:23970cf718ee | 257 | pc.printf("currletter %c \n", currletter); |
aismail1997 | 25:23970cf718ee | 258 | pc.printf("braille %s \n", buttonarr.getBraille(currletter)); |
aismail1997 | 25:23970cf718ee | 259 | } |
aismail1997 | 25:23970cf718ee | 260 | int* pinsup = buttonarr.pinsUp('M'); |
aismail1997 | 25:23970cf718ee | 261 | pc.printf("pins up M: %d \n", pinsup[0]); |
aismail1997 | 25:23970cf718ee | 262 | pc.printf("pins up M: %d \n", pinsup[1]); |
aismail1997 | 25:23970cf718ee | 263 | pc.printf("pins up M: %d \n", pinsup[2]); |
aismail1997 | 25:23970cf718ee | 264 | int* wrongpins = buttonarr.wrongPins('M', 'O'); |
aismail1997 | 25:23970cf718ee | 265 | pc.printf("wrong pins M & O %d \n", wrongpins[0]); |
aismail1997 | 25:23970cf718ee | 266 | pc.printf("wrong pins M & O %d \n", wrongpins[1]); |
aismail1997 | 25:23970cf718ee | 267 | //pc.printf("current braille %c \n", buttonarr.checkVal()); |
aismail1997 | 24:6931917c70cd | 268 | //pc.printf("%c\n", buttonarr.releaseButtons()); |
aismail1997 | 21:ceac47be2e64 | 269 | |
nnguyen45 | 26:4b2940eec275 | 270 | |
nnguyen45 | 26:4b2940eec275 | 271 | //TEXT-TO-SPEECH LOGIC |
nnguyen45 | 26:4b2940eec275 | 272 | myTTS.volume(18); //max volume |
nnguyen45 | 26:4b2940eec275 | 273 | string repeat = "Please try again."; |
nnguyen45 | 26:4b2940eec275 | 274 | |
nnguyen45 | 27:0ed2a9cad0e1 | 275 | myTTS.speakf("SWelcome to Bat, the Braille Assistive Teacher. This device will help you learn how to write and type braille.\r"); // Send the desired string to convert to speech |
nnguyen45 | 26:4b2940eec275 | 276 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
nnguyen45 | 27:0ed2a9cad0e1 | 277 | for(int i = 0; i < lettersize; i++) { //iterate through the letter array |
nnguyen45 | 26:4b2940eec275 | 278 | int* pinsup = buttonarr.pinsUp('M'); |
nnguyen45 | 26:4b2940eec275 | 279 | int currpress; |
nnguyen45 | 27:0ed2a9cad0e1 | 280 | int numpinsups = pinsup[0]; // size of array is first element of pinsup |
nnguyen45 | 27:0ed2a9cad0e1 | 281 | //string presspin; |
nnguyen45 | 27:0ed2a9cad0e1 | 282 | string presspin = "STo write the letter "; |
nnguyen45 | 27:0ed2a9cad0e1 | 283 | presspin = presspin + letter[i]; |
nnguyen45 | 27:0ed2a9cad0e1 | 284 | presspin = presspin + ", press pins"; |
nnguyen45 | 27:0ed2a9cad0e1 | 285 | pc.printf("numpinsups %d", numpinsups); |
nnguyen45 | 26:4b2940eec275 | 286 | |
nnguyen45 | 27:0ed2a9cad0e1 | 287 | for (int j = 1; j <= numpinsups; j++) { // get what pins to press |
nnguyen45 | 27:0ed2a9cad0e1 | 288 | currpress = pinsup[j]; |
nnguyen45 | 27:0ed2a9cad0e1 | 289 | switch (currpress) { |
nnguyen45 | 27:0ed2a9cad0e1 | 290 | case 1: |
nnguyen45 | 27:0ed2a9cad0e1 | 291 | presspin = presspin + " 1"; |
nnguyen45 | 27:0ed2a9cad0e1 | 292 | break; |
nnguyen45 | 27:0ed2a9cad0e1 | 293 | case 2: |
nnguyen45 | 27:0ed2a9cad0e1 | 294 | presspin = presspin + " 2"; |
nnguyen45 | 27:0ed2a9cad0e1 | 295 | break; |
nnguyen45 | 27:0ed2a9cad0e1 | 296 | case 3: |
nnguyen45 | 27:0ed2a9cad0e1 | 297 | presspin = presspin + " 3"; |
nnguyen45 | 27:0ed2a9cad0e1 | 298 | break; |
nnguyen45 | 27:0ed2a9cad0e1 | 299 | case 4: |
nnguyen45 | 27:0ed2a9cad0e1 | 300 | presspin = presspin + " 4"; |
nnguyen45 | 27:0ed2a9cad0e1 | 301 | break; |
nnguyen45 | 27:0ed2a9cad0e1 | 302 | case 5: |
nnguyen45 | 27:0ed2a9cad0e1 | 303 | presspin = presspin + " 5"; |
nnguyen45 | 27:0ed2a9cad0e1 | 304 | break; |
nnguyen45 | 27:0ed2a9cad0e1 | 305 | case 6: |
nnguyen45 | 27:0ed2a9cad0e1 | 306 | presspin = presspin + " 6"; |
nnguyen45 | 27:0ed2a9cad0e1 | 307 | break; |
nnguyen45 | 27:0ed2a9cad0e1 | 308 | } |
nnguyen45 | 26:4b2940eec275 | 309 | |
nnguyen45 | 26:4b2940eec275 | 310 | } |
nnguyen45 | 26:4b2940eec275 | 311 | myTTS.speakf("S%s\r",presspin); |
nnguyen45 | 26:4b2940eec275 | 312 | |
nnguyen45 | 26:4b2940eec275 | 313 | } |
nnguyen45 | 27:0ed2a9cad0e1 | 314 | //myTTS.speakf("STo write the letter %s, press pins %D\r",letter[i]); |
nnguyen45 | 26:4b2940eec275 | 315 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
aismail1997 | 24:6931917c70cd | 316 | |
nnguyen45 | 27:0ed2a9cad0e1 | 317 | /* |
nnguyen45 | 27:0ed2a9cad0e1 | 318 | //check pins pressed |
nnguyen45 | 26:4b2940eec275 | 319 | if(incorrect) { |
nnguyen45 | 26:4b2940eec275 | 320 | myTTS.speakf("SPin %D is incoorect.\r",ID); |
nnguyen45 | 26:4b2940eec275 | 321 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
nnguyen45 | 26:4b2940eec275 | 322 | myTTS.speakf("S%s.\r", repeat); |
nnguyen45 | 26:4b2940eec275 | 323 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
nnguyen45 | 26:4b2940eec275 | 324 | } |
nnguyen45 | 26:4b2940eec275 | 325 | } |
nnguyen45 | 26:4b2940eec275 | 326 | for(int i = 0; i < word.length(); i++) //iterate through the word array |
nnguyen45 | 26:4b2940eec275 | 327 | { |
nnguyen45 | 26:4b2940eec275 | 328 | myTTS.speakf("SWrite the word %s, press pins %D\r",word[i], ID); |
nnguyen45 | 26:4b2940eec275 | 329 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
nnguyen45 | 26:4b2940eec275 | 330 | //check pins pressed |
nnguyen45 | 26:4b2940eec275 | 331 | if(incorrect) { |
nnguyen45 | 26:4b2940eec275 | 332 | myTTS.speakf("SPin %D is incoorect.\r",ID); |
nnguyen45 | 26:4b2940eec275 | 333 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
nnguyen45 | 26:4b2940eec275 | 334 | myTTS.speakf("S%s.\r", repeat); |
nnguyen45 | 26:4b2940eec275 | 335 | myTTS.ready(); //ready waits for speech to finish from last command with a ":" response |
nnguyen45 | 26:4b2940eec275 | 336 | } |
nnguyen45 | 26:4b2940eec275 | 337 | } |
nnguyen45 | 27:0ed2a9cad0e1 | 338 | */ |
nnguyen45 | 26:4b2940eec275 | 339 | |
nnguyen45 | 26:4b2940eec275 | 340 | |
nnguyen45 | 26:4b2940eec275 | 341 | |
nnguyen45 | 26:4b2940eec275 | 342 | |
nnguyen45 | 26:4b2940eec275 | 343 | |
nnguyen45 | 26:4b2940eec275 | 344 | |
nnguyen45 | 26:4b2940eec275 | 345 | |
nnguyen45 | 26:4b2940eec275 | 346 | |
nnguyen45 | 26:4b2940eec275 | 347 | // MAIN THREAD |
nnguyen45 | 26:4b2940eec275 | 348 | while(true) |
nnguyen45 | 26:4b2940eec275 | 349 | { |
nnguyen45 | 26:4b2940eec275 | 350 | |
nnguyen45 | 26:4b2940eec275 | 351 | // read linear potentiometer |
nnguyen45 | 26:4b2940eec275 | 352 | //led4 = linpot; |
nnguyen45 | 26:4b2940eec275 | 353 | |
nnguyen45 | 26:4b2940eec275 | 354 | Thread::wait(500); // wait till thread is done |
nnguyen45 | 26:4b2940eec275 | 355 | } |
aismail1997 | 2:9eda4611081a | 356 | } |