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