Words in Typing mode FINAL
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_Type_word by
Revision 31:e5024aeca3a7, committed 2017-11-17
- Comitter:
- nnguyen45
- Date:
- Fri Nov 17 16:24:33 2017 +0000
- Parent:
- 30:79cdf893c8b8
- Child:
- 32:e87bb6e83072
- Commit message:
- code to check for incorrect button and reset working
Changed in this revision
| buttonArray.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/buttonArray.cpp Fri Nov 17 15:17:36 2017 +0000
+++ b/buttonArray.cpp Fri Nov 17 16:24:33 2017 +0000
@@ -7,7 +7,7 @@
buttonArray::buttonArray(button b1, button b2, button b3, button b4, button b5, button b6)
: button1(b1), button2(b2), button3(b3), button4(b4), button5(b5), button6(b6) {}
-//Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX);
// FUNCTIONS
@@ -15,7 +15,7 @@
// braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
char buttonArray::checkVal()
{
- //pc.printf(" checkVal \n");
+ pc.printf(" checkVal \n");
char* braille;
char val = NULL;
sprintf(braille, "%d%d%d%d%d%d", button1.getPress(), button2.getPress(),
@@ -50,7 +50,7 @@
if (strcmp(braille, "011111") == 0) val = 'Z';*/
// check if reset
if (strcmp(braille, "111111") == 0) val = 'Z';
- //pc.printf(" %c \n", val);
+ pc.printf(" %c \n", val);
return val;
}
@@ -95,10 +95,10 @@
char* inarr = getBraille(input);
//pc.printf("input %s\n", inarr);
char* actarr = getBraille(actual);
- //pc.printf("wrong pins");
+ pc.printf("wrong pins");
int j = 1;
for (int i = 0; i < 6; i++) {
- if(inarr[i] != actarr[i]) {
+ if(inarr[i] == actarr[i]) {
wrong[j] = i+1;
//pc.printf("%d ", wrong[j]);
j++;
--- a/main.cpp Fri Nov 17 15:17:36 2017 +0000
+++ b/main.cpp Fri Nov 17 16:24:33 2017 +0000
@@ -132,7 +132,7 @@
int main()
{
-
+
// SETUP
// pull up the pushbutton to prevent bouncing
pb1.mode(PullUp);
@@ -251,7 +251,7 @@
//TEXT-TO-SPEECH LOGIC
myTTS.volume(18); //max volume
- string repeat = "Please try again.";
+ myTTS.voice(2);
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
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
@@ -264,7 +264,7 @@
//string presspin;
string presspin = "STo write the letter ";
presspin = presspin + letter[i];
- presspin = presspin + ", press pins";
+ presspin = presspin + ", press buttons";
for (int j = 1; j < numpinsups; j++) { // get what pins to press
currpress = pinsup[j];
@@ -292,14 +292,79 @@
myTTS.speakf("%s\r",presspin);
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
wait(1);
-
+ //pc.printf("hello");
+
+
+
+ //WORKS UP TO HERE
char userinput = buttonarr.checkVal();
+ //pc.printf("userinput: %c", userinput);
// get input
//pc.printf("Your input was: %c", userinput);
-
+ int currwrong;
+ string wrongpin;
// check result
int* wrongpins = buttonarr.wrongPins(userinput, currletter);
-
+ //string presspin;
+ //wrongpins[0] != 1
+ int test = 1;
+ while(test == 1) {
+ //pc.printf("In while loop");
+ wrongpin = "SYour answer is incorrect. Buttons";
+ //wrongpin = wrongpin + letter[i];
+ //wrongpin = wrongpin + ", press pins";
+ for (int j = 1; j < wrongpins[0]; j++) { // get what pins are wrong
+ currwrong = wrongpins[j];
+ //pc.printf("currwrong: %d", currwrong);
+ switch (currwrong) {
+ case 1:
+ wrongpin = wrongpin + " 1,";
+ break;
+ case 2:
+ wrongpin = wrongpin + " 2,";
+ break;
+ case 3:
+ wrongpin = wrongpin + " 3,";
+ break;
+ case 4:
+ wrongpin = wrongpin + " 4,";
+ break;
+ case 5:
+ wrongpin = wrongpin + " 5,";
+ break;
+ case 6:
+ wrongpin = wrongpin + " 6,";
+ break;
+ }
+ }
+ //pc.printf("end for loop");
+ wrongpin = wrongpin + " are wrong. Please try again.";
+ myTTS.speakf("%s\r",wrongpin);
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ //UPDATE THE PINS THAT ARE WRONG BY CHECKING AGAIN BELOW
+ userinput = buttonarr.checkVal();
+ // get input
+ //pc.printf("Your input was: %c", userinput);
+
+ // check result
+ wrongpins = buttonarr.wrongPins(userinput, currletter);
+ test = 0;
+ }
+ myTTS.speakf("SGood job! Your answer is correct.\r");
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ int reset = 1;
+ myTTS.speakf("SNow reset the device by pressing down all the buttons.\r");
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ while(reset == 1) {
+ userinput = buttonarr.checkVal();
+ if(userinput == 'X') {
+ reset = 0;
+ } else {
+ reset = 0;
+ myTTS.speakf("SNot all of the buttons were reset. Please try again.\r");
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ }
+ }
//pc.printf("wrongpins are: %d", wrongpins[0]);
}
//myTTS.speakf("STo write the letter %s, press pins %D\r",letter[i]);
