Working reset, flipped logic

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Nhi by BAT

Committer:
nnguyen45
Date:
Mon Nov 20 15:46:11 2017 +0000
Revision:
32:e87bb6e83072
Parent:
31:e5024aeca3a7
Child:
33:3090ec93b4aa
code demo to Dr. Howard

Who changed what in which revision?

UserRevisionLine numberNew 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);
aismail1997 30:79cdf893c8b8 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();
aismail1997 21:c5df903f068a 64 //led4 = button1.getLp();
aismail1997 19:ceac47be2e64 65 Thread::wait(100); // wait till thread is done
aismail1997 10:21268d8bf979 66 }
aismail1997 14:581a3b02f4c3 67 }
aismail1997 14:581a3b02f4c3 68
aismail1997 14:581a3b02f4c3 69 void button2_thread()
aismail1997 14:581a3b02f4c3 70 {
aismail1997 14:581a3b02f4c3 71 while(true) {
aismail1997 19:ceac47be2e64 72 state2 = button2.updateState();
nnguyen45 32:e87bb6e83072 73 Thread::wait(200); // wait till thread is done
aismail1997 10:21268d8bf979 74 }
aismail1997 4:cc181f8f2bd1 75 }
aismail1997 4:cc181f8f2bd1 76
aismail1997 18:d14bf57f435b 77 // thread for the custom button
aismail1997 18:d14bf57f435b 78 void button3_thread()
aismail1997 18:d14bf57f435b 79 {
aismail1997 18:d14bf57f435b 80 while(true) {
aismail1997 19:ceac47be2e64 81 state3 = button3.updateState();
nnguyen45 32:e87bb6e83072 82 Thread::wait(200); // wait till thread is done
aismail1997 18:d14bf57f435b 83 }
aismail1997 18:d14bf57f435b 84 }
aismail1997 18:d14bf57f435b 85
aismail1997 18:d14bf57f435b 86 // thread for the custom button
aismail1997 18:d14bf57f435b 87 void button4_thread()
aismail1997 18:d14bf57f435b 88 {
aismail1997 18:d14bf57f435b 89 while(true) {
aismail1997 19:ceac47be2e64 90 state4 = button4.updateState();
nnguyen45 32:e87bb6e83072 91 Thread::wait(200); // wait till thread is done
aismail1997 18:d14bf57f435b 92 }
aismail1997 18:d14bf57f435b 93 }
aismail1997 18:d14bf57f435b 94
aismail1997 18:d14bf57f435b 95 // thread for the custom button
aismail1997 18:d14bf57f435b 96 void button5_thread()
aismail1997 18:d14bf57f435b 97 {
aismail1997 18:d14bf57f435b 98 while(true) {
aismail1997 19:ceac47be2e64 99 state5 = button5.updateState();
nnguyen45 32:e87bb6e83072 100 Thread::wait(200); // wait till thread is done
aismail1997 18:d14bf57f435b 101 }
aismail1997 18:d14bf57f435b 102 }
aismail1997 18:d14bf57f435b 103
aismail1997 18:d14bf57f435b 104 // thread for the custom button
aismail1997 18:d14bf57f435b 105 void button6_thread()
aismail1997 18:d14bf57f435b 106 {
aismail1997 18:d14bf57f435b 107 while(true) {
aismail1997 19:ceac47be2e64 108 state6 = button6.updateState();
nnguyen45 32:e87bb6e83072 109 Thread::wait(200); // wait till thread is done
aismail1997 18:d14bf57f435b 110 }
aismail1997 18:d14bf57f435b 111 }
aismail1997 18:d14bf57f435b 112
aismail1997 6:1aa86ad19af9 113 void submit_thread()
aismail1997 4:cc181f8f2bd1 114 {
aismail1997 13:b80dde24e9bc 115 Thread::wait(500); // wait till thread is done
aismail1997 4:cc181f8f2bd1 116 }
aismail1997 4:cc181f8f2bd1 117
aismail1997 6:1aa86ad19af9 118 void start_thread()
aismail1997 4:cc181f8f2bd1 119 {
aismail1997 6:1aa86ad19af9 120 // read pb_start
aismail1997 6:1aa86ad19af9 121 // if 1
aismail1997 14:581a3b02f4c3 122 start = 1;
aismail1997 14:581a3b02f4c3 123 //pc.printf("start %d ", start);
aismail1997 6:1aa86ad19af9 124 // else 0
aismail1997 13:b80dde24e9bc 125 Thread::wait(500); // wait till thread is done
aismail1997 4:cc181f8f2bd1 126 }
aismail1997 0:9eda4611081a 127
aismail1997 14:581a3b02f4c3 128
aismail1997 0:9eda4611081a 129 int main()
aismail1997 0:9eda4611081a 130 {
aismail1997 6:1aa86ad19af9 131 // SETUP
aismail1997 4:cc181f8f2bd1 132 // pull up the pushbutton to prevent bouncing
aismail1997 16:5c91af9b4e7c 133 pb1.mode(PullUp);
aismail1997 16:5c91af9b4e7c 134 pb2.mode(PullUp);
aismail1997 18:d14bf57f435b 135 pb3.mode(PullUp);
aismail1997 18:d14bf57f435b 136 pb4.mode(PullUp);
aismail1997 18:d14bf57f435b 137 pb5.mode(PullUp);
aismail1997 18:d14bf57f435b 138 pb6.mode(PullUp);
aismail1997 30:79cdf893c8b8 139 wait(.001);
aismail1997 15:7e9308d14faa 140
aismail1997 22:6931917c70cd 141 // servos begin at 30 degrees
aismail1997 10:21268d8bf979 142 // replace with a button setup function
nnguyen45 32:e87bb6e83072 143 buttonarr.setup();
aismail1997 19:ceac47be2e64 144
aismail1997 18:d14bf57f435b 145 //led1 = 1;
aismail1997 16:5c91af9b4e7c 146 //led2 = 1;
aismail1997 30:79cdf893c8b8 147 Thread t1(button_thread);
nnguyen45 32:e87bb6e83072 148 Thread t2(button2_thread);
aismail1997 18:d14bf57f435b 149 Thread t3(button3_thread);
aismail1997 18:d14bf57f435b 150 Thread t4(button4_thread);
aismail1997 18:d14bf57f435b 151 Thread t5(button5_thread);
aismail1997 30:79cdf893c8b8 152 //Thread t6(button6_thread);
aismail1997 18:d14bf57f435b 153 t1.start(button_thread);
nnguyen45 32:e87bb6e83072 154 t2.start(button2_thread);
aismail1997 18:d14bf57f435b 155 t3.start(button3_thread);
aismail1997 18:d14bf57f435b 156 t4.start(button4_thread);
aismail1997 18:d14bf57f435b 157 t5.start(button5_thread);
aismail1997 30:79cdf893c8b8 158 //t6.start(button6_thread);
aismail1997 23:23970cf718ee 159
aismail1997 23:23970cf718ee 160 // PARSE INPUT FILE FOR LETTERS AND WORDS
aismail1997 23:23970cf718ee 161 char delimiter = ',';
aismail1997 29:b9bd85682db1 162 // TODO: fix the letters
aismail1997 23:23970cf718ee 163 string letter[2];
aismail1997 23:23970cf718ee 164 string word[2];
aismail1997 23:23970cf718ee 165 char check;
aismail1997 23:23970cf718ee 166 string temp;
aismail1997 23:23970cf718ee 167 string tempword = "";
aismail1997 23:23970cf718ee 168 int counter = 0;
aismail1997 23:23970cf718ee 169 FILE *fp = fopen("/sd/plan.txt", "r"); //create file
aismail1997 23:23970cf718ee 170 if(fp == NULL) {
aismail1997 30:79cdf893c8b8 171 //pc.printf("Could not open file for write\n");
aismail1997 23:23970cf718ee 172 }
aismail1997 23:23970cf718ee 173 check = fgetc(fp); //grabs a char from file
aismail1997 23:23970cf718ee 174 while(check != '\n') { //while not at the end of line for letters
aismail1997 23:23970cf718ee 175 if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored
aismail1997 23:23970cf718ee 176 letter[counter] = temp; //write letter
aismail1997 30:79cdf893c8b8 177 //pc.printf("Letter: %s \n", letter[counter]);
aismail1997 23:23970cf718ee 178 counter = counter + 1; //increment counter
aismail1997 23:23970cf718ee 179 } else {
aismail1997 23:23970cf718ee 180 temp = check; //store letter
aismail1997 23:23970cf718ee 181 }
aismail1997 23:23970cf718ee 182 check = fgetc(fp); //grabs next char
aismail1997 23:23970cf718ee 183 }
aismail1997 23:23970cf718ee 184 counter = 0; //reset counter
aismail1997 23:23970cf718ee 185 check = fgetc(fp); //grabs next char
aismail1997 23:23970cf718ee 186 while(!feof(fp)) { //while not at the end of line for words
aismail1997 23:23970cf718ee 187 if(check == delimiter) { //when at the comma at the end of a word
aismail1997 23:23970cf718ee 188 word[counter] = tempword; //write word
aismail1997 30:79cdf893c8b8 189 //pc.printf("Word: %s \n", word[counter]);
aismail1997 23:23970cf718ee 190 tempword = "";
aismail1997 23:23970cf718ee 191 counter = counter + 1; //increment counter
aismail1997 23:23970cf718ee 192 } else {
aismail1997 23:23970cf718ee 193 tempword = tempword + check; //concatenate letters to build word
aismail1997 23:23970cf718ee 194 }
aismail1997 23:23970cf718ee 195 check = fgetc(fp); //grabs next char
aismail1997 23:23970cf718ee 196 }
aismail1997 23:23970cf718ee 197 fclose(fp); //close file
aismail1997 14:581a3b02f4c3 198
aismail1997 14:581a3b02f4c3 199 // start threads for reset, mode, start
aismail1997 14:581a3b02f4c3 200 //Thread t1(start_thread);
aismail1997 14:581a3b02f4c3 201 //pc.printf("start thread");
aismail1997 14:581a3b02f4c3 202 //Thread t2(submit_thread);
aismail1997 14:581a3b02f4c3 203 // setup SDcard and Speaker
aismail1997 14:581a3b02f4c3 204
aismail1997 14:581a3b02f4c3 205 // when started
aismail1997 14:581a3b02f4c3 206 //while (start == 0){}
aismail1997 14:581a3b02f4c3 207 //Thread t3(button_thread);
aismail1997 14:581a3b02f4c3 208 //pc.printf("button thread");
aismail1997 14:581a3b02f4c3 209 //Thread t4(button2_thread);
aismail1997 14:581a3b02f4c3 210 //pc.printf("button2 thread");
aismail1997 14:581a3b02f4c3 211
aismail1997 14:581a3b02f4c3 212 //Thread t3(submit_thread);
aismail1997 14:581a3b02f4c3 213
aismail1997 14:581a3b02f4c3 214 // when submitted
aismail1997 14:581a3b02f4c3 215 //while (submit == 0) {}
aismail1997 14:581a3b02f4c3 216
aismail1997 14:581a3b02f4c3 217 // start button threads and submit thread
aismail1997 14:581a3b02f4c3 218 // if submit close button threads and submit thread
aismail1997 14:581a3b02f4c3 219 // check result
aismail1997 14:581a3b02f4c3 220 // play results on speaker
aismail1997 14:581a3b02f4c3 221 // save results
aismail1997 29:b9bd85682db1 222
aismail1997 23:23970cf718ee 223 char currletter;
aismail1997 23:23970cf718ee 224 int lettersize = sizeof(letter)/sizeof(letter[0]);
aismail1997 23:23970cf718ee 225 for (int i = 0; i < lettersize; i++) {
aismail1997 23:23970cf718ee 226 currletter = letter[i][0];
aismail1997 30:79cdf893c8b8 227 //pc.printf("currletter %c \n", currletter);
aismail1997 30:79cdf893c8b8 228 //pc.printf("braille %s \n", buttonarr.getBraille(currletter));
aismail1997 23:23970cf718ee 229 }
aismail1997 29:b9bd85682db1 230
aismail1997 30:79cdf893c8b8 231 /*int* pinsup = buttonarr.pinsUp('M');
aismail1997 27:b2e53ce54b3e 232 int currpress;
aismail1997 27:b2e53ce54b3e 233 // get what pins to press
aismail1997 27:b2e53ce54b3e 234 for (int i = 1; i <= pinsup[0]; i++) {
aismail1997 27:b2e53ce54b3e 235 // speaker stuff
aismail1997 27:b2e53ce54b3e 236 currpress = pinsup[i];
aismail1997 30:79cdf893c8b8 237 }*/
aismail1997 27:b2e53ce54b3e 238
aismail1997 30:79cdf893c8b8 239 /*int* wrongpins = buttonarr.wrongPins('M', 'O');
aismail1997 27:b2e53ce54b3e 240 int currwrong;
aismail1997 27:b2e53ce54b3e 241 // get what pins are wrong
aismail1997 27:b2e53ce54b3e 242 for (int i = 1; i <= wrongpins[0]; i++) {
aismail1997 27:b2e53ce54b3e 243 // speaker stuff
aismail1997 27:b2e53ce54b3e 244 currwrong = wrongpins[i];
aismail1997 30:79cdf893c8b8 245 }*/
aismail1997 29:b9bd85682db1 246
aismail1997 28:3c4ebc4fde0f 247 //TEXT-TO-SPEECH LOGIC
aismail1997 28:3c4ebc4fde0f 248 myTTS.volume(18); //max volume
nnguyen45 31:e5024aeca3a7 249 myTTS.voice(2);
aismail1997 28:3c4ebc4fde0f 250
aismail1997 28:3c4ebc4fde0f 251 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 28:3c4ebc4fde0f 252 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 28:3c4ebc4fde0f 253 for(int i = 0; i < lettersize; i++) { //iterate through the letter array
aismail1997 29:b9bd85682db1 254 char currletter = letter[i][0];
aismail1997 30:79cdf893c8b8 255 //pc.printf("letter: %c \n", currletter);
aismail1997 29:b9bd85682db1 256 int* pinsup = buttonarr.pinsUp(currletter);
aismail1997 28:3c4ebc4fde0f 257 int currpress;
aismail1997 28:3c4ebc4fde0f 258 int numpinsups = pinsup[0]; // size of array is first element of pinsup
aismail1997 28:3c4ebc4fde0f 259 //string presspin;
aismail1997 28:3c4ebc4fde0f 260 string presspin = "STo write the letter ";
aismail1997 28:3c4ebc4fde0f 261 presspin = presspin + letter[i];
nnguyen45 31:e5024aeca3a7 262 presspin = presspin + ", press buttons";
aismail1997 28:3c4ebc4fde0f 263
aismail1997 28:3c4ebc4fde0f 264 for (int j = 1; j < numpinsups; j++) { // get what pins to press
aismail1997 28:3c4ebc4fde0f 265 currpress = pinsup[j];
aismail1997 28:3c4ebc4fde0f 266 switch (currpress) {
aismail1997 28:3c4ebc4fde0f 267 case 1:
aismail1997 28:3c4ebc4fde0f 268 presspin = presspin + " 1,";
aismail1997 28:3c4ebc4fde0f 269 break;
aismail1997 28:3c4ebc4fde0f 270 case 2:
aismail1997 28:3c4ebc4fde0f 271 presspin = presspin + " 2,";
aismail1997 28:3c4ebc4fde0f 272 break;
aismail1997 28:3c4ebc4fde0f 273 case 3:
aismail1997 28:3c4ebc4fde0f 274 presspin = presspin + " 3,";
aismail1997 28:3c4ebc4fde0f 275 break;
aismail1997 28:3c4ebc4fde0f 276 case 4:
aismail1997 28:3c4ebc4fde0f 277 presspin = presspin + " 4,";
aismail1997 28:3c4ebc4fde0f 278 break;
aismail1997 28:3c4ebc4fde0f 279 case 5:
aismail1997 28:3c4ebc4fde0f 280 presspin = presspin + " 5,";
aismail1997 28:3c4ebc4fde0f 281 break;
aismail1997 28:3c4ebc4fde0f 282 case 6:
aismail1997 28:3c4ebc4fde0f 283 presspin = presspin + " 6,";
aismail1997 28:3c4ebc4fde0f 284 break;
aismail1997 28:3c4ebc4fde0f 285 }
aismail1997 28:3c4ebc4fde0f 286 }
aismail1997 29:b9bd85682db1 287 myTTS.speakf("%s\r",presspin);
aismail1997 29:b9bd85682db1 288 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 30:79cdf893c8b8 289 wait(1);
nnguyen45 31:e5024aeca3a7 290 //pc.printf("hello");
nnguyen45 31:e5024aeca3a7 291
nnguyen45 31:e5024aeca3a7 292 //WORKS UP TO HERE
aismail1997 30:79cdf893c8b8 293 char userinput = buttonarr.checkVal();
nnguyen45 31:e5024aeca3a7 294 //pc.printf("userinput: %c", userinput);
aismail1997 30:79cdf893c8b8 295 // get input
aismail1997 30:79cdf893c8b8 296 //pc.printf("Your input was: %c", userinput);
nnguyen45 31:e5024aeca3a7 297 int currwrong;
nnguyen45 31:e5024aeca3a7 298 string wrongpin;
aismail1997 30:79cdf893c8b8 299 // check result
aismail1997 30:79cdf893c8b8 300 int* wrongpins = buttonarr.wrongPins(userinput, currletter);
nnguyen45 31:e5024aeca3a7 301 //string presspin;
nnguyen45 31:e5024aeca3a7 302 //wrongpins[0] != 1
nnguyen45 31:e5024aeca3a7 303 int test = 1;
nnguyen45 31:e5024aeca3a7 304 while(test == 1) {
nnguyen45 31:e5024aeca3a7 305 //pc.printf("In while loop");
nnguyen45 31:e5024aeca3a7 306 wrongpin = "SYour answer is incorrect. Buttons";
nnguyen45 31:e5024aeca3a7 307 //wrongpin = wrongpin + letter[i];
nnguyen45 31:e5024aeca3a7 308 //wrongpin = wrongpin + ", press pins";
nnguyen45 31:e5024aeca3a7 309 for (int j = 1; j < wrongpins[0]; j++) { // get what pins are wrong
nnguyen45 31:e5024aeca3a7 310 currwrong = wrongpins[j];
nnguyen45 31:e5024aeca3a7 311 //pc.printf("currwrong: %d", currwrong);
nnguyen45 31:e5024aeca3a7 312 switch (currwrong) {
nnguyen45 31:e5024aeca3a7 313 case 1:
nnguyen45 31:e5024aeca3a7 314 wrongpin = wrongpin + " 1,";
nnguyen45 31:e5024aeca3a7 315 break;
nnguyen45 31:e5024aeca3a7 316 case 2:
nnguyen45 31:e5024aeca3a7 317 wrongpin = wrongpin + " 2,";
nnguyen45 31:e5024aeca3a7 318 break;
nnguyen45 31:e5024aeca3a7 319 case 3:
nnguyen45 31:e5024aeca3a7 320 wrongpin = wrongpin + " 3,";
nnguyen45 31:e5024aeca3a7 321 break;
nnguyen45 31:e5024aeca3a7 322 case 4:
nnguyen45 31:e5024aeca3a7 323 wrongpin = wrongpin + " 4,";
nnguyen45 31:e5024aeca3a7 324 break;
nnguyen45 31:e5024aeca3a7 325 case 5:
nnguyen45 31:e5024aeca3a7 326 wrongpin = wrongpin + " 5,";
nnguyen45 31:e5024aeca3a7 327 break;
nnguyen45 31:e5024aeca3a7 328 case 6:
nnguyen45 31:e5024aeca3a7 329 wrongpin = wrongpin + " 6,";
nnguyen45 31:e5024aeca3a7 330 break;
nnguyen45 31:e5024aeca3a7 331 }
nnguyen45 31:e5024aeca3a7 332 }
nnguyen45 31:e5024aeca3a7 333 //pc.printf("end for loop");
nnguyen45 31:e5024aeca3a7 334 wrongpin = wrongpin + " are wrong. Please try again.";
nnguyen45 31:e5024aeca3a7 335 myTTS.speakf("%s\r",wrongpin);
nnguyen45 31:e5024aeca3a7 336 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
nnguyen45 31:e5024aeca3a7 337 //UPDATE THE PINS THAT ARE WRONG BY CHECKING AGAIN BELOW
nnguyen45 31:e5024aeca3a7 338 userinput = buttonarr.checkVal();
nnguyen45 31:e5024aeca3a7 339 // get input
nnguyen45 31:e5024aeca3a7 340 //pc.printf("Your input was: %c", userinput);
nnguyen45 31:e5024aeca3a7 341
nnguyen45 31:e5024aeca3a7 342 // check result
nnguyen45 31:e5024aeca3a7 343 wrongpins = buttonarr.wrongPins(userinput, currletter);
nnguyen45 31:e5024aeca3a7 344 test = 0;
nnguyen45 31:e5024aeca3a7 345 }
nnguyen45 31:e5024aeca3a7 346 myTTS.speakf("SGood job! Your answer is correct.\r");
nnguyen45 31:e5024aeca3a7 347 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
nnguyen45 31:e5024aeca3a7 348 int reset = 1;
nnguyen45 31:e5024aeca3a7 349 myTTS.speakf("SNow reset the device by pressing down all the buttons.\r");
nnguyen45 31:e5024aeca3a7 350 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
nnguyen45 31:e5024aeca3a7 351 while(reset == 1) {
nnguyen45 31:e5024aeca3a7 352 userinput = buttonarr.checkVal();
nnguyen45 31:e5024aeca3a7 353 if(userinput == 'X') {
nnguyen45 31:e5024aeca3a7 354 reset = 0;
nnguyen45 31:e5024aeca3a7 355 } else {
nnguyen45 31:e5024aeca3a7 356 reset = 0;
nnguyen45 31:e5024aeca3a7 357 myTTS.speakf("SNot all of the buttons were reset. Please try again.\r");
nnguyen45 31:e5024aeca3a7 358 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
nnguyen45 31:e5024aeca3a7 359 }
nnguyen45 31:e5024aeca3a7 360 }
aismail1997 30:79cdf893c8b8 361 //pc.printf("wrongpins are: %d", wrongpins[0]);
aismail1997 28:3c4ebc4fde0f 362 }
aismail1997 28:3c4ebc4fde0f 363 //myTTS.speakf("STo write the letter %s, press pins %D\r",letter[i]);
aismail1997 29:b9bd85682db1 364 //myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 28:3c4ebc4fde0f 365
nnguyen45 32:e87bb6e83072 366 //buttonarr.releaseButtons();
aismail1997 23:23970cf718ee 367 //pc.printf("current braille %c \n", buttonarr.checkVal());
aismail1997 22:6931917c70cd 368 //pc.printf("%c\n", buttonarr.releaseButtons());
aismail1997 19:ceac47be2e64 369
aismail1997 6:1aa86ad19af9 370 // MAIN THREAD
aismail1997 6:1aa86ad19af9 371 while(true) {
aismail1997 22:6931917c70cd 372
aismail1997 22:6931917c70cd 373 // read linear potentiometer
aismail1997 22:6931917c70cd 374 //led4 = linpot;
aismail1997 22:6931917c70cd 375
aismail1997 14:581a3b02f4c3 376 Thread::wait(500); // wait till thread is done
aismail1997 0:9eda4611081a 377 }
aismail1997 0:9eda4611081a 378 }