working type letter with mode button

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_Type_letter by BAT

Committer:
nnguyen45
Date:
Sat Dec 02 01:49:48 2017 +0000
Revision:
38:68f7f54b723b
Parent:
37:d873136dfb12
Child:
39:8cc80f0b4398
Trying to separate typing mode from read/write mode

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);
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();
nnguyen45 32:e87bb6e83072 75 Thread::wait(200); // wait till thread is done
aismail1997 10:21268d8bf979 76 }
aismail1997 4:cc181f8f2bd1 77 }
aismail1997 4:cc181f8f2bd1 78
aismail1997 18:d14bf57f435b 79 // thread for the custom button
aismail1997 18:d14bf57f435b 80 void button3_thread()
aismail1997 18:d14bf57f435b 81 {
aismail1997 18:d14bf57f435b 82 while(true) {
aismail1997 19:ceac47be2e64 83 state3 = button3.updateState();
nnguyen45 32:e87bb6e83072 84 Thread::wait(200); // wait till thread is done
aismail1997 18:d14bf57f435b 85 }
aismail1997 18:d14bf57f435b 86 }
aismail1997 18:d14bf57f435b 87
aismail1997 18:d14bf57f435b 88 // thread for the custom button
aismail1997 18:d14bf57f435b 89 void button4_thread()
aismail1997 18:d14bf57f435b 90 {
aismail1997 18:d14bf57f435b 91 while(true) {
aismail1997 19:ceac47be2e64 92 state4 = button4.updateState();
nnguyen45 32:e87bb6e83072 93 Thread::wait(200); // wait till thread is done
aismail1997 18:d14bf57f435b 94 }
aismail1997 18:d14bf57f435b 95 }
aismail1997 18:d14bf57f435b 96
aismail1997 18:d14bf57f435b 97 // thread for the custom button
aismail1997 18:d14bf57f435b 98 void button5_thread()
aismail1997 18:d14bf57f435b 99 {
aismail1997 18:d14bf57f435b 100 while(true) {
aismail1997 19:ceac47be2e64 101 state5 = button5.updateState();
nnguyen45 32:e87bb6e83072 102 Thread::wait(200); // wait till thread is done
aismail1997 18:d14bf57f435b 103 }
aismail1997 18:d14bf57f435b 104 }
aismail1997 18:d14bf57f435b 105
aismail1997 18:d14bf57f435b 106 // thread for the custom button
aismail1997 18:d14bf57f435b 107 void button6_thread()
aismail1997 18:d14bf57f435b 108 {
aismail1997 18:d14bf57f435b 109 while(true) {
aismail1997 19:ceac47be2e64 110 state6 = button6.updateState();
nnguyen45 32:e87bb6e83072 111 Thread::wait(200); // wait till thread is done
aismail1997 18:d14bf57f435b 112 }
aismail1997 18:d14bf57f435b 113 }
aismail1997 18:d14bf57f435b 114
aismail1997 6:1aa86ad19af9 115 void submit_thread()
aismail1997 4:cc181f8f2bd1 116 {
aismail1997 13:b80dde24e9bc 117 Thread::wait(500); // wait till thread is done
aismail1997 4:cc181f8f2bd1 118 }
aismail1997 4:cc181f8f2bd1 119
aismail1997 6:1aa86ad19af9 120 void start_thread()
aismail1997 4:cc181f8f2bd1 121 {
aismail1997 6:1aa86ad19af9 122 // read pb_start
aismail1997 6:1aa86ad19af9 123 // if 1
aismail1997 14:581a3b02f4c3 124 start = 1;
aismail1997 14:581a3b02f4c3 125 //pc.printf("start %d ", start);
aismail1997 6:1aa86ad19af9 126 // else 0
aismail1997 13:b80dde24e9bc 127 Thread::wait(500); // wait till thread is done
aismail1997 4:cc181f8f2bd1 128 }
aismail1997 0:9eda4611081a 129
aismail1997 14:581a3b02f4c3 130
aismail1997 0:9eda4611081a 131 int main()
aismail1997 0:9eda4611081a 132 {
aismail1997 6:1aa86ad19af9 133 // SETUP
aismail1997 4:cc181f8f2bd1 134 // pull up the pushbutton to prevent bouncing
aismail1997 16:5c91af9b4e7c 135 pb1.mode(PullUp);
aismail1997 16:5c91af9b4e7c 136 pb2.mode(PullUp);
aismail1997 18:d14bf57f435b 137 pb3.mode(PullUp);
aismail1997 18:d14bf57f435b 138 pb4.mode(PullUp);
aismail1997 18:d14bf57f435b 139 pb5.mode(PullUp);
aismail1997 18:d14bf57f435b 140 pb6.mode(PullUp);
aismail1997 30:79cdf893c8b8 141 wait(.001);
aismail1997 15:7e9308d14faa 142
aismail1997 22:6931917c70cd 143 // servos begin at 30 degrees
aismail1997 10:21268d8bf979 144 // replace with a button setup function
nnguyen45 38:68f7f54b723b 145 //buttonarr.setup();
aismail1997 37:d873136dfb12 146 //buttonarr.setMode();
aismail1997 19:ceac47be2e64 147
aismail1997 18:d14bf57f435b 148 //led1 = 1;
aismail1997 16:5c91af9b4e7c 149 //led2 = 1;
nnguyen45 33:3090ec93b4aa 150
aismail1997 23:23970cf718ee 151
aismail1997 23:23970cf718ee 152 // PARSE INPUT FILE FOR LETTERS AND WORDS
aismail1997 23:23970cf718ee 153 char delimiter = ',';
aismail1997 29:b9bd85682db1 154 // TODO: fix the letters
aismail1997 23:23970cf718ee 155 string letter[2];
aismail1997 23:23970cf718ee 156 string word[2];
aismail1997 23:23970cf718ee 157 char check;
aismail1997 23:23970cf718ee 158 string temp;
aismail1997 23:23970cf718ee 159 string tempword = "";
aismail1997 23:23970cf718ee 160 int counter = 0;
aismail1997 23:23970cf718ee 161 FILE *fp = fopen("/sd/plan.txt", "r"); //create file
aismail1997 23:23970cf718ee 162 if(fp == NULL) {
aismail1997 30:79cdf893c8b8 163 //pc.printf("Could not open file for write\n");
aismail1997 23:23970cf718ee 164 }
aismail1997 23:23970cf718ee 165 check = fgetc(fp); //grabs a char from file
aismail1997 23:23970cf718ee 166 while(check != '\n') { //while not at the end of line for letters
aismail1997 23:23970cf718ee 167 if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored
aismail1997 23:23970cf718ee 168 letter[counter] = temp; //write letter
aismail1997 30:79cdf893c8b8 169 //pc.printf("Letter: %s \n", letter[counter]);
aismail1997 23:23970cf718ee 170 counter = counter + 1; //increment counter
aismail1997 23:23970cf718ee 171 } else {
aismail1997 23:23970cf718ee 172 temp = check; //store letter
aismail1997 23:23970cf718ee 173 }
aismail1997 23:23970cf718ee 174 check = fgetc(fp); //grabs next char
aismail1997 23:23970cf718ee 175 }
aismail1997 23:23970cf718ee 176 counter = 0; //reset counter
aismail1997 23:23970cf718ee 177 check = fgetc(fp); //grabs next char
aismail1997 23:23970cf718ee 178 while(!feof(fp)) { //while not at the end of line for words
aismail1997 23:23970cf718ee 179 if(check == delimiter) { //when at the comma at the end of a word
aismail1997 23:23970cf718ee 180 word[counter] = tempword; //write word
aismail1997 30:79cdf893c8b8 181 //pc.printf("Word: %s \n", word[counter]);
aismail1997 23:23970cf718ee 182 tempword = "";
aismail1997 23:23970cf718ee 183 counter = counter + 1; //increment counter
aismail1997 23:23970cf718ee 184 } else {
aismail1997 23:23970cf718ee 185 tempword = tempword + check; //concatenate letters to build word
aismail1997 23:23970cf718ee 186 }
aismail1997 23:23970cf718ee 187 check = fgetc(fp); //grabs next char
aismail1997 23:23970cf718ee 188 }
aismail1997 23:23970cf718ee 189 fclose(fp); //close file
aismail1997 14:581a3b02f4c3 190
nnguyen45 33:3090ec93b4aa 191 Thread t1(button_thread);
nnguyen45 33:3090ec93b4aa 192 Thread t2(button2_thread);
nnguyen45 33:3090ec93b4aa 193 Thread t3(button3_thread);
nnguyen45 33:3090ec93b4aa 194 Thread t4(button4_thread);
nnguyen45 33:3090ec93b4aa 195 Thread t5(button5_thread);
nnguyen45 33:3090ec93b4aa 196 //Thread t6(button6_thread);
nnguyen45 33:3090ec93b4aa 197 t1.start(button_thread);
nnguyen45 33:3090ec93b4aa 198 t2.start(button2_thread);
nnguyen45 33:3090ec93b4aa 199 t3.start(button3_thread);
nnguyen45 33:3090ec93b4aa 200 t4.start(button4_thread);
nnguyen45 33:3090ec93b4aa 201 t5.start(button5_thread);
nnguyen45 33:3090ec93b4aa 202 //t6.start(button6_thread);
aismail1997 34:1248dfa0740b 203
aismail1997 23:23970cf718ee 204 char currletter;
aismail1997 23:23970cf718ee 205 int lettersize = sizeof(letter)/sizeof(letter[0]);
aismail1997 37:d873136dfb12 206 int type = 0;
aismail1997 34:1248dfa0740b 207
aismail1997 28:3c4ebc4fde0f 208 //TEXT-TO-SPEECH LOGIC
nnguyen45 38:68f7f54b723b 209 myTTS.volume(1); //max volume is 18
nnguyen45 31:e5024aeca3a7 210 myTTS.voice(2);
aismail1997 28:3c4ebc4fde0f 211
nnguyen45 38:68f7f54b723b 212 /*
nnguyen45 36:593bae6b342b 213 char* braille;
nnguyen45 36:593bae6b342b 214 char userinput;
nnguyen45 36:593bae6b342b 215
nnguyen45 36:593bae6b342b 216 // INITIAL RESET
aismail1997 37:d873136dfb12 217 if (type == 0) {
aismail1997 37:d873136dfb12 218 int reset = 1;
nnguyen45 38:68f7f54b723b 219 myTTS.speakf("SWelcome to Bat, the Braille Assistive Teacher. This device will help you learn how to write and type braille. Please setup the device by pressing down all the buttons.\r");
aismail1997 37:d873136dfb12 220 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 37:d873136dfb12 221 while(reset == 1) {
nnguyen45 38:68f7f54b723b 222 wait(3);
aismail1997 37:d873136dfb12 223 sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
aismail1997 37:d873136dfb12 224 button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
aismail1997 37:d873136dfb12 225 userinput = buttonarr.checkVal(braille);
aismail1997 37:d873136dfb12 226 if(userinput == 'Z') {
aismail1997 37:d873136dfb12 227 reset = 0;
aismail1997 37:d873136dfb12 228 } else {
aismail1997 37:d873136dfb12 229 //reset = 0;
aismail1997 37:d873136dfb12 230 myTTS.speakf("SSetup failed. Please try again.\r");
aismail1997 37:d873136dfb12 231 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 37:d873136dfb12 232 }
nnguyen45 36:593bae6b342b 233 }
nnguyen45 36:593bae6b342b 234 }
nnguyen45 36:593bae6b342b 235
aismail1997 28:3c4ebc4fde0f 236 for(int i = 0; i < lettersize; i++) { //iterate through the letter array
aismail1997 29:b9bd85682db1 237 char currletter = letter[i][0];
aismail1997 30:79cdf893c8b8 238 //pc.printf("letter: %c \n", currletter);
aismail1997 29:b9bd85682db1 239 int* pinsup = buttonarr.pinsUp(currletter);
aismail1997 28:3c4ebc4fde0f 240 int currpress;
aismail1997 28:3c4ebc4fde0f 241 int numpinsups = pinsup[0]; // size of array is first element of pinsup
aismail1997 28:3c4ebc4fde0f 242 //string presspin;
aismail1997 28:3c4ebc4fde0f 243 string presspin = "STo write the letter ";
aismail1997 28:3c4ebc4fde0f 244 presspin = presspin + letter[i];
nnguyen45 31:e5024aeca3a7 245 presspin = presspin + ", press buttons";
aismail1997 28:3c4ebc4fde0f 246
aismail1997 28:3c4ebc4fde0f 247 for (int j = 1; j < numpinsups; j++) { // get what pins to press
aismail1997 28:3c4ebc4fde0f 248 currpress = pinsup[j];
aismail1997 28:3c4ebc4fde0f 249 switch (currpress) {
aismail1997 28:3c4ebc4fde0f 250 case 1:
aismail1997 28:3c4ebc4fde0f 251 presspin = presspin + " 1,";
aismail1997 28:3c4ebc4fde0f 252 break;
aismail1997 28:3c4ebc4fde0f 253 case 2:
aismail1997 28:3c4ebc4fde0f 254 presspin = presspin + " 2,";
aismail1997 28:3c4ebc4fde0f 255 break;
aismail1997 28:3c4ebc4fde0f 256 case 3:
aismail1997 28:3c4ebc4fde0f 257 presspin = presspin + " 3,";
aismail1997 28:3c4ebc4fde0f 258 break;
aismail1997 28:3c4ebc4fde0f 259 case 4:
aismail1997 28:3c4ebc4fde0f 260 presspin = presspin + " 4,";
aismail1997 28:3c4ebc4fde0f 261 break;
aismail1997 28:3c4ebc4fde0f 262 case 5:
aismail1997 28:3c4ebc4fde0f 263 presspin = presspin + " 5,";
aismail1997 28:3c4ebc4fde0f 264 break;
aismail1997 28:3c4ebc4fde0f 265 case 6:
aismail1997 28:3c4ebc4fde0f 266 presspin = presspin + " 6,";
aismail1997 28:3c4ebc4fde0f 267 break;
aismail1997 28:3c4ebc4fde0f 268 }
aismail1997 28:3c4ebc4fde0f 269 }
aismail1997 29:b9bd85682db1 270 myTTS.speakf("%s\r",presspin);
aismail1997 29:b9bd85682db1 271 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
nnguyen45 38:68f7f54b723b 272 wait(2);
nnguyen45 31:e5024aeca3a7 273 //pc.printf("hello");
nnguyen45 31:e5024aeca3a7 274
nnguyen45 31:e5024aeca3a7 275 //WORKS UP TO HERE
aismail1997 34:1248dfa0740b 276 char* braille;
aismail1997 37:d873136dfb12 277 char userinput;
aismail1997 37:d873136dfb12 278 char* oldbraille;
aismail1997 37:d873136dfb12 279 if (type == 0) {
aismail1997 37:d873136dfb12 280 sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
aismail1997 37:d873136dfb12 281 button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
aismail1997 37:d873136dfb12 282 userinput = buttonarr.checkVal(braille);
aismail1997 37:d873136dfb12 283 } else {
aismail1997 37:d873136dfb12 284 // TYPE MODE
aismail1997 37:d873136dfb12 285 sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(),
aismail1997 37:d873136dfb12 286 !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress());
aismail1997 37:d873136dfb12 287 userinput = buttonarr.checkVal(braille);
aismail1997 37:d873136dfb12 288 oldbraille = braille;
aismail1997 37:d873136dfb12 289 }
aismail1997 37:d873136dfb12 290
nnguyen45 31:e5024aeca3a7 291 int currwrong;
nnguyen45 31:e5024aeca3a7 292 string wrongpin;
aismail1997 30:79cdf893c8b8 293 // check result
aismail1997 34:1248dfa0740b 294 pc.printf("\n %c %c", userinput, currletter);
aismail1997 34:1248dfa0740b 295 int* wrongpins = buttonarr.wrongPins(braille, currletter);
nnguyen45 31:e5024aeca3a7 296 int test = 1;
nnguyen45 31:e5024aeca3a7 297 while(test == 1) {
nnguyen45 31:e5024aeca3a7 298 //pc.printf("In while loop");
nnguyen45 31:e5024aeca3a7 299 wrongpin = "SYour answer is incorrect. Buttons";
nnguyen45 31:e5024aeca3a7 300 //wrongpin = wrongpin + letter[i];
nnguyen45 31:e5024aeca3a7 301 //wrongpin = wrongpin + ", press pins";
nnguyen45 31:e5024aeca3a7 302 for (int j = 1; j < wrongpins[0]; j++) { // get what pins are wrong
nnguyen45 31:e5024aeca3a7 303 currwrong = wrongpins[j];
nnguyen45 31:e5024aeca3a7 304 //pc.printf("currwrong: %d", currwrong);
nnguyen45 31:e5024aeca3a7 305 switch (currwrong) {
nnguyen45 31:e5024aeca3a7 306 case 1:
nnguyen45 31:e5024aeca3a7 307 wrongpin = wrongpin + " 1,";
nnguyen45 31:e5024aeca3a7 308 break;
nnguyen45 31:e5024aeca3a7 309 case 2:
nnguyen45 31:e5024aeca3a7 310 wrongpin = wrongpin + " 2,";
nnguyen45 31:e5024aeca3a7 311 break;
nnguyen45 31:e5024aeca3a7 312 case 3:
nnguyen45 31:e5024aeca3a7 313 wrongpin = wrongpin + " 3,";
nnguyen45 31:e5024aeca3a7 314 break;
nnguyen45 31:e5024aeca3a7 315 case 4:
nnguyen45 31:e5024aeca3a7 316 wrongpin = wrongpin + " 4,";
nnguyen45 31:e5024aeca3a7 317 break;
nnguyen45 31:e5024aeca3a7 318 case 5:
nnguyen45 31:e5024aeca3a7 319 wrongpin = wrongpin + " 5,";
nnguyen45 31:e5024aeca3a7 320 break;
nnguyen45 31:e5024aeca3a7 321 case 6:
nnguyen45 31:e5024aeca3a7 322 wrongpin = wrongpin + " 6,";
nnguyen45 31:e5024aeca3a7 323 break;
nnguyen45 31:e5024aeca3a7 324 }
nnguyen45 31:e5024aeca3a7 325 }
nnguyen45 31:e5024aeca3a7 326 //pc.printf("end for loop");
aismail1997 34:1248dfa0740b 327 if (wrongpins[0] > 1) {
aismail1997 34:1248dfa0740b 328 wrongpin = wrongpin + " are wrong. Please try again.";
aismail1997 34:1248dfa0740b 329 myTTS.speakf("%s\r",wrongpin);
aismail1997 34:1248dfa0740b 330 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
nnguyen45 38:68f7f54b723b 331 wait(2);
aismail1997 34:1248dfa0740b 332 //UPDATE THE PINS THAT ARE WRONG BY CHECKING AGAIN BELOW
aismail1997 34:1248dfa0740b 333 //char* braille;
aismail1997 37:d873136dfb12 334 if (type == 0) {
aismail1997 37:d873136dfb12 335 sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
aismail1997 37:d873136dfb12 336 button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
aismail1997 37:d873136dfb12 337 userinput = buttonarr.checkVal(braille);
aismail1997 37:d873136dfb12 338 } else {
aismail1997 37:d873136dfb12 339 // TYPE MODE
aismail1997 37:d873136dfb12 340 sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
aismail1997 37:d873136dfb12 341 button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
aismail1997 37:d873136dfb12 342 userinput = buttonarr.checkVal(braille);
aismail1997 37:d873136dfb12 343 }
aismail1997 34:1248dfa0740b 344 // get input
aismail1997 34:1248dfa0740b 345 //pc.printf("Your input was: %c", userinput);
nnguyen45 31:e5024aeca3a7 346
aismail1997 34:1248dfa0740b 347 // check result
aismail1997 34:1248dfa0740b 348 wrongpins = buttonarr.wrongPins(braille, currletter);
aismail1997 34:1248dfa0740b 349 } else {
aismail1997 34:1248dfa0740b 350 test = 0;
aismail1997 37:d873136dfb12 351 myTTS.speakf("SGood job!\r");
aismail1997 34:1248dfa0740b 352 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 34:1248dfa0740b 353 }
nnguyen45 31:e5024aeca3a7 354 }
aismail1997 34:1248dfa0740b 355
aismail1997 37:d873136dfb12 356 if (type == 0) {
aismail1997 37:d873136dfb12 357 int reset = 1;
aismail1997 37:d873136dfb12 358 myTTS.speakf("SNow reset by pressing down all the buttons.\r");
aismail1997 37:d873136dfb12 359 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 37:d873136dfb12 360 while(reset == 1) {
aismail1997 37:d873136dfb12 361 char* braille;
aismail1997 37:d873136dfb12 362 sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
aismail1997 37:d873136dfb12 363 button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
aismail1997 37:d873136dfb12 364 userinput = buttonarr.checkVal(braille);
aismail1997 37:d873136dfb12 365 if(userinput == 'Z') {
aismail1997 37:d873136dfb12 366 reset = 0;
aismail1997 37:d873136dfb12 367 } else {
nnguyen45 38:68f7f54b723b 368 wait(2);
aismail1997 37:d873136dfb12 369 myTTS.speakf("SPlease try again.\r");
aismail1997 37:d873136dfb12 370 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 37:d873136dfb12 371 }
nnguyen45 31:e5024aeca3a7 372 }
nnguyen45 31:e5024aeca3a7 373 }
aismail1997 30:79cdf893c8b8 374 //pc.printf("wrongpins are: %d", wrongpins[0]);
nnguyen45 38:68f7f54b723b 375 }*/
aismail1997 37:d873136dfb12 376
aismail1997 37:d873136dfb12 377 // WORD CODE
aismail1997 37:d873136dfb12 378
aismail1997 37:d873136dfb12 379 // WORD COUNTER
aismail1997 37:d873136dfb12 380 // go through each word
aismail1997 37:d873136dfb12 381 // go through each letter in the word
aismail1997 37:d873136dfb12 382 // get user input
aismail1997 37:d873136dfb12 383 // when buttons reset - save previous letter
aismail1997 37:d873136dfb12 384 // loop until submit button is pressed
aismail1997 37:d873136dfb12 385 // compare words
aismail1997 37:d873136dfb12 386 // check what letters were wrong
aismail1997 37:d873136dfb12 387 // give wrong letters - correct spelling is...
aismail1997 37:d873136dfb12 388
nnguyen45 38:68f7f54b723b 389 //SETTING UP SERVOS TO RELEASE FOR TYPING MODE FREEZES THE CODE
nnguyen45 38:68f7f54b723b 390 buttonarr.setup(); //Reset servos so that buttons are up for typing mode
aismail1997 37:d873136dfb12 391 string currword;
aismail1997 37:d873136dfb12 392 int wordsize = sizeof(word)/sizeof(word[0]);
aismail1997 37:d873136dfb12 393
nnguyen45 38:68f7f54b723b 394 //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 395 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 396 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 37:d873136dfb12 397 for(int i = 0; i < wordsize; i++) { //iterate through the word array
aismail1997 37:d873136dfb12 398 currword = word[i];
aismail1997 37:d873136dfb12 399 string presspin = "To type the word ";
aismail1997 37:d873136dfb12 400 presspin = presspin + word[i];
aismail1997 37:d873136dfb12 401 presspin = presspin + ", type letters ";
aismail1997 37:d873136dfb12 402 for (int j = 0; j < currword.length(); j++) {
aismail1997 37:d873136dfb12 403 presspin = presspin + ", "+ currword[j];
aismail1997 37:d873136dfb12 404 }
nnguyen45 38:68f7f54b723b 405 //myTTS.speakf("S%s\r", presspin); //UNCOMMENTING HERE WILL MESS UP READ/WRITE CODE
aismail1997 37:d873136dfb12 406 //myTTS.ready();
aismail1997 37:d873136dfb12 407 }
aismail1997 37:d873136dfb12 408
nnguyen45 38:68f7f54b723b 409
aismail1997 37:d873136dfb12 410 // loop through each of the words
aismail1997 37:d873136dfb12 411 for(int i = 0; i < wordsize; i++) { //iterate through the word array
aismail1997 37:d873136dfb12 412 currword = word[i];
aismail1997 37:d873136dfb12 413 string presspin = "To type the word ";
aismail1997 37:d873136dfb12 414 presspin = presspin + word[i];
aismail1997 37:d873136dfb12 415 presspin = presspin + ", type letters ";
aismail1997 37:d873136dfb12 416 for (int j = 0; j < currword.length(); j++) {
aismail1997 37:d873136dfb12 417 presspin = presspin + ", "+ currword[j];
aismail1997 37:d873136dfb12 418 }
aismail1997 37:d873136dfb12 419 myTTS.speakf("S%s\r", presspin);
aismail1997 37:d873136dfb12 420 myTTS.ready();
aismail1997 37:d873136dfb12 421
aismail1997 37:d873136dfb12 422 string wordinput = "";
aismail1997 28:3c4ebc4fde0f 423
aismail1997 37:d873136dfb12 424 // loop through each of the letters
aismail1997 37:d873136dfb12 425 //olduserinput;
aismail1997 37:d873136dfb12 426 int incorrect = 1;
aismail1997 37:d873136dfb12 427 //char userinput;
aismail1997 37:d873136dfb12 428 //char* braille;
aismail1997 37:d873136dfb12 429
aismail1997 37:d873136dfb12 430 // while(!submit)
aismail1997 37:d873136dfb12 431 while (incorrect) {
aismail1997 37:d873136dfb12 432 // replace for loop with submit
aismail1997 37:d873136dfb12 433 // while (!submit) {
aismail1997 37:d873136dfb12 434 for (int j = 0; j < currword.length(); j++) {
aismail1997 37:d873136dfb12 435 //currletter = currword[j];
aismail1997 37:d873136dfb12 436 // check if all buttons were pressed
aismail1997 37:d873136dfb12 437 wait(1);
aismail1997 37:d873136dfb12 438
aismail1997 37:d873136dfb12 439 char* braille;
aismail1997 37:d873136dfb12 440 char* oldbraille;
aismail1997 37:d873136dfb12 441
aismail1997 37:d873136dfb12 442 // wait for input
aismail1997 37:d873136dfb12 443 while (strcmp(braille, "000000") == 0) {}
aismail1997 19:ceac47be2e64 444
aismail1997 37:d873136dfb12 445 // while buttons have not been released
aismail1997 37:d873136dfb12 446 while (strcmp(braille, "000000") != 0) {
aismail1997 37:d873136dfb12 447 oldbraille = braille;
aismail1997 37:d873136dfb12 448 sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
aismail1997 37:d873136dfb12 449 button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());
aismail1997 37:d873136dfb12 450 }
aismail1997 37:d873136dfb12 451
aismail1997 37:d873136dfb12 452 // at the end of this, oldbraille contains the letter representation
aismail1997 37:d873136dfb12 453 // flip braille values
aismail1997 37:d873136dfb12 454 //userinput = checkVal(oldbraille);
aismail1997 37:d873136dfb12 455 wordinput[j] = buttonarr.checkVal(oldbraille);
aismail1997 37:d873136dfb12 456 //wordinput[j] = olduserinput;
aismail1997 37:d873136dfb12 457 }
aismail1997 22:6931917c70cd 458
aismail1997 37:d873136dfb12 459 // check result of words
aismail1997 37:d873136dfb12 460 if (wordinput.compare(currword) == 0) { // input is correct
aismail1997 37:d873136dfb12 461 incorrect = 0;
aismail1997 37:d873136dfb12 462 myTTS.speakf("Good job!\r");
aismail1997 37:d873136dfb12 463 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 37:d873136dfb12 464 } else {
aismail1997 37:d873136dfb12 465 incorrect = 0; // delete this line
aismail1997 37:d873136dfb12 466 myTTS.speakf("SPlease try again!.\r");
aismail1997 37:d873136dfb12 467 myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
aismail1997 37:d873136dfb12 468 }
aismail1997 37:d873136dfb12 469 }
aismail1997 37:d873136dfb12 470
nnguyen45 38:68f7f54b723b 471 }
aismail1997 37:d873136dfb12 472
aismail1997 37:d873136dfb12 473 // MAIN THREAD
aismail1997 37:d873136dfb12 474 while(true) {
aismail1997 22:6931917c70cd 475
aismail1997 14:581a3b02f4c3 476 Thread::wait(500); // wait till thread is done
aismail1997 0:9eda4611081a 477 }
aismail1997 0:9eda4611081a 478 }