Working read code with mode button
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_senior_design_Testnew by
Diff: main.cpp
- Revision:
- 32:79cdf893c8b8
- Parent:
- 31:b9bd85682db1
- Child:
- 33:e5024aeca3a7
--- a/main.cpp Wed Nov 15 16:42:48 2017 +0000 +++ b/main.cpp Fri Nov 17 15:17:36 2017 +0000 @@ -29,7 +29,7 @@ //DigitalOut led4(LED4); DigitalIn linpot(p9); -Serial pc(USBTX, USBRX); +//Serial pc(USBTX, USBRX); SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card //AnalogOut DACout(p26); //wave_player waver(&DACout); @@ -132,7 +132,7 @@ int main() { - /* + // SETUP // pull up the pushbutton to prevent bouncing pb1.mode(PullUp); @@ -141,26 +141,26 @@ pb4.mode(PullUp); pb5.mode(PullUp); pb6.mode(PullUp); - wait(.001); */ + wait(.001); // servos begin at 30 degrees // replace with a button setup function - buttonarr.setup(); + //buttonarr.setup(); //led1 = 1; //led2 = 1; - /*Thread t1(button_thread); - Thread t2(button2_thread); + Thread t1(button_thread); + //Thread t2(button2_thread); Thread t3(button3_thread); Thread t4(button4_thread); Thread t5(button5_thread); - Thread t6(button6_thread); + //Thread t6(button6_thread); t1.start(button_thread); - t2.start(button2_thread); + //t2.start(button2_thread); t3.start(button3_thread); t4.start(button4_thread); t5.start(button5_thread); - t6.start(button6_thread);*/ + //t6.start(button6_thread); // PARSE INPUT FILE FOR LETTERS AND WORDS char delimiter = ','; @@ -173,13 +173,13 @@ int counter = 0; FILE *fp = fopen("/sd/plan.txt", "r"); //create file if(fp == NULL) { - pc.printf("Could not open file for write\n"); + //pc.printf("Could not open file for write\n"); } check = fgetc(fp); //grabs a char from file while(check != '\n') { //while not at the end of line for letters if((check == delimiter) && (temp.length() == 1)) { //at a comma and have a letter stored letter[counter] = temp; //write letter - pc.printf("Letter: %s \n", letter[counter]); + //pc.printf("Letter: %s \n", letter[counter]); counter = counter + 1; //increment counter } else { temp = check; //store letter @@ -191,7 +191,7 @@ while(!feof(fp)) { //while not at the end of line for words if(check == delimiter) { //when at the comma at the end of a word word[counter] = tempword; //write word - pc.printf("Word: %s \n", word[counter]); + //pc.printf("Word: %s \n", word[counter]); tempword = ""; counter = counter + 1; //increment counter } else { @@ -227,28 +227,27 @@ char currletter; int lettersize = sizeof(letter)/sizeof(letter[0]); - pc.printf("lettersize %d \n", lettersize); for (int i = 0; i < lettersize; i++) { currletter = letter[i][0]; - pc.printf("currletter %c \n", currletter); - pc.printf("braille %s \n", buttonarr.getBraille(currletter)); + //pc.printf("currletter %c \n", currletter); + //pc.printf("braille %s \n", buttonarr.getBraille(currletter)); } - int* pinsup = buttonarr.pinsUp('M'); + /*int* pinsup = buttonarr.pinsUp('M'); int currpress; // get what pins to press for (int i = 1; i <= pinsup[0]; i++) { // speaker stuff currpress = pinsup[i]; - } + }*/ - int* wrongpins = buttonarr.wrongPins('M', 'O'); + /*int* wrongpins = buttonarr.wrongPins('M', 'O'); int currwrong; // get what pins are wrong for (int i = 1; i <= wrongpins[0]; i++) { // speaker stuff currwrong = wrongpins[i]; - } + }*/ //TEXT-TO-SPEECH LOGIC myTTS.volume(18); //max volume @@ -258,7 +257,7 @@ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response for(int i = 0; i < lettersize; i++) { //iterate through the letter array char currletter = letter[i][0]; - pc.printf("letter: %c \n", currletter); + //pc.printf("letter: %c \n", currletter); int* pinsup = buttonarr.pinsUp(currletter); int currpress; int numpinsups = pinsup[0]; // size of array is first element of pinsup @@ -292,6 +291,16 @@ } myTTS.speakf("%s\r",presspin); myTTS.ready(); //ready waits for speech to finish from last command with a ":" response + wait(1); + + char userinput = buttonarr.checkVal(); + // get input + //pc.printf("Your input was: %c", userinput); + + // check result + int* wrongpins = buttonarr.wrongPins(userinput, currletter); + + //pc.printf("wrongpins are: %d", wrongpins[0]); } //myTTS.speakf("STo write the letter %s, press pins %D\r",letter[i]); //myTTS.ready(); //ready waits for speech to finish from last command with a ":" response