Working read code with mode button

Dependencies:   SDFileSystem emic2 mbed-rtos mbed

Fork of BAT_senior_design_Testnew by BAT

Committer:
nnguyen45
Date:
Tue Dec 05 03:31:58 2017 +0000
Revision:
43:82d67fb53e61
Parent:
42:44a898adef26
Working with mode button

Who changed what in which revision?

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