Letters in typing mode
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_Type_letter by
Revision 41:560ee7866781, committed 2017-12-03
- Comitter:
- aismail1997
- Date:
- Sun Dec 03 23:44:27 2017 +0000
- Parent:
- 40:85be3490d3a7
- Child:
- 42:bdb6f132a609
- Commit message:
- letter and write mode work independently;
Changed in this revision
--- a/button.cpp Sun Dec 03 23:10:29 2017 +0000
+++ b/button.cpp Sun Dec 03 23:44:27 2017 +0000
@@ -10,62 +10,15 @@
// button constructor
button::button(PwmOut servo, DigitalIn pb, int id)
: servo(servo), pb(pb), state(0), press(0), id(id), type(0) {}
-/*button::button(PwmOut servo, DigitalIn pb, AnalogIn lp)
- : servo(servo), pb(pb), linpot(lp), press(0), state(0) {}
-*/
-//Serial pc(USBTX, USBRX);
-
+
// FUNCTIONS
-// get servo pin
-PwmOut button::getServoPin()
-{
- return servo;
-}
-
-// get servo pin
-void button::setState(int mystate)
-{
- state = mystate;
-}
-
-void button::setPress(int mypress)
-{
- press = mypress;
-}
-
-// get servo pin
-/*void button::setMode(int mymode)
-{
- mode = mymode;
-}*/
-
-// get current state of the button
-int button::getState()
-{
- return state;
-}
-
-int button::getID()
-{
- return id;
-}
-
-
int button::getPress()
{
//pc.printf("%d", press);
return press;
}
-// get current state of the button
-int button::getLp()
-{
- /* if (linpot < 2)
- return 1;
- else*/
- return 0;
-}
// move servo into the slot
void button::moveServoIn()
--- a/button.h Sun Dec 03 23:10:29 2017 +0000
+++ b/button.h Sun Dec 03 23:44:27 2017 +0000
@@ -24,19 +24,19 @@
// button(PwmOut servo, DigitalIn pb, AnalogIn linpot);
// functions
- PwmOut getServoPin(); // get the servo pin
+ //PwmOut getServoPin(); // get the servo pin
//void setState(int state); // set state
//void setMode(int mode); // set mode
- void setState(int); // set what state the button is in - up or down
+ //void setState(int); // set what state the button is in - up or down
void setPress(int); // set the button press
void setMode(int); // set what state the button is in - up or down
void moveServoIn(); // move servo into the slot
void moveServoOut(); // move servo out of the slot
- int getID();
+ //int getID();
int updateState();
- int getState();
+ //int getState();
int getPress();
- int getLp();
+ //int getLp();
void setup();
};
--- a/buttonArray.cpp Sun Dec 03 23:10:29 2017 +0000
+++ b/buttonArray.cpp Sun Dec 03 23:44:27 2017 +0000
@@ -15,24 +15,18 @@
// braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII
char buttonArray::checkVal(char* braille)
{
- //pc.printf(" checkVal \n");
- //char* braille;
char val = 'K';
- /*int test = button1.getPress();
- sprintf(braille, "%d%d%d%d%d%d", test, button2.getPress(),
- button3.getPress(), button4.getPress(), button5.getPress(), button6.getPress());*/
- //pc.printf(" %s \n", braille);
if (strcmp(braille, "000000") == 0) val = 'X';
if (strcmp(braille, "011111") == 0) val = 'A';
- if (strcmp(braille, "001111") == 0) val = 'B';
- if (strcmp(braille, "011011") == 0) val = 'C';
+ //if (strcmp(braille, "001111") == 0) val = 'B';
+ //if (strcmp(braille, "011011") == 0) val = 'C';
if (strcmp(braille, "011001") == 0) val = 'D';
- if (strcmp(braille, "011101") == 0) val = 'E';
- if (strcmp(braille, "001011") == 0) val = 'F';
- if (strcmp(braille, "001001") == 0) val = 'G';
- if (strcmp(braille, "001101") == 0) val = 'H';
- if (strcmp(braille, "101101") == 0) val = 'I';
- if (strcmp(braille, "101001") == 0) val = 'J';
+ //if (strcmp(braille, "011101") == 0) val = 'E';
+ //if (strcmp(braille, "001011") == 0) val = 'F';
+ //if (strcmp(braille, "001001") == 0) val = 'G';
+ //if (strcmp(braille, "001101") == 0) val = 'H';
+ //if (strcmp(braille, "101101") == 0) val = 'I';
+ //if (strcmp(braille, "101001") == 0) val = 'J';
if (strcmp(braille, "010011") == 0) val = 'M';
if (strcmp(braille, "010101") == 0) val = 'O';
/*if (strcmp(braille, "011111") == 0) val = 'K';
@@ -111,41 +105,6 @@
return wrong;
}
-// release buttons
-void buttonArray::releaseButtons()
-{
- if (button1.getPress()) {
- button1.moveServoOut();
- button1.setState(3);
- button1.setPress(0);
- }
- if (button2.getPress()) {
- button2.moveServoOut();
- button2.setState(3);
- button2.setPress(0);
- }
- if (button3.getPress()) {
- button3.moveServoOut();
- button3.setState(3);
- button3.setPress(0);
- }
- if (button4.getPress()) {
- button4.moveServoOut();
- button4.setState(3);
- button4.setPress(0);
- }
- if (button5.getPress()) {
- button5.moveServoOut();
- button5.setState(3);
- button5.setPress(0);
- }
- if (button6.getPress()) {
- button6.moveServoOut();
- button6.setState(3);
- button6.setPress(0);
- }
-}
-
void buttonArray::setup()
{
// servos begin at 30 degrees
--- a/buttonArray.h Sun Dec 03 23:10:29 2017 +0000
+++ b/buttonArray.h Sun Dec 03 23:44:27 2017 +0000
@@ -22,7 +22,6 @@
// functions
int* wrongPins(char* input, char actual);
char checkVal(char* braille); // return buttons ascii representation
- void releaseButtons();// release all buttons;
int* pinsUp(char val);
char* getBraille(char val);
void setup();
--- a/main.cpp Sun Dec 03 23:10:29 2017 +0000
+++ b/main.cpp Sun Dec 03 23:44:27 2017 +0000
@@ -168,14 +168,162 @@
t5.start(button5_thread);
//t6.start(button6_thread);
- char currletter;
+ //char currletter;
int lettersize = sizeof(letter)/sizeof(letter[0]);
- int type = 0;
+ //int type = 0;
//TEXT-TO-SPEECH LOGIC
- myTTS.volume(1); //max volume is 18
+ myTTS.volume(3); //max volume is 18
myTTS.voice(2);
+ // SETUP
+ /* buttonarr.setup(); //Reset servos so that buttons are up for typing mode
+ button1.setMode(1);
+ button2.setMode(1);
+ button3.setMode(1);
+ button4.setMode(1);
+ button5.setMode(1);
+ button6.setMode(1);
+
+// LETTER CODE
+// tell how to type letter
+// wait for input
+// check if correct letter
+// feedback
+// loop
+
+ for(int i = 0; i < lettersize; i++) { //iterate through the letter array
+ char currletter = letter[i][0];
+ int* pinsup = buttonarr.pinsUp(currletter);
+ int currpress;
+ int numpinsups = pinsup[0]; // size of array is first element of pinsup
+ string presspin = "STo write the letter ";
+ presspin = presspin + letter[i];
+ presspin = presspin + ", press buttons";
+
+ for (int j = 1; j < numpinsups; j++) { // get what pins to press
+ currpress = pinsup[j];
+ switch (currpress) {
+ case 1:
+ presspin = presspin + " 1,";
+ break;
+ case 2:
+ presspin = presspin + " 2,";
+ break;
+ case 3:
+ presspin = presspin + " 3,";
+ break;
+ case 4:
+ presspin = presspin + " 4,";
+ break;
+ case 5:
+ presspin = presspin + " 5,";
+ break;
+ case 6:
+ presspin = presspin + " 6,";
+ break;
+ }
+ }
+ myTTS.speakf("%s\r",presspin);
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ //wait(2);
+
+ //WORKS UP TO HERE
+ char* braille;
+ char* oldbraille;
+
+ // TYPE MODE
+ sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(),
+ !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress());
+
+ // wait for input
+ while (strcmp(braille, "111111") == 0) {
+ sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(),
+ !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress());
+ }
+
+ // while buttons have not been released
+ int oldsum = 0;
+ int sum = 0;
+ while ((strcmp(braille, "111111") != 0) && (oldsum <= sum)) {
+ oldbraille = braille;
+ oldsum = sum;
+ sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(),
+ !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress());
+ sum = button1.getPress() + button2.getPress() + button3.getPress() + button4.getPress()
+ + button5.getPress() + button6.getPress();
+ }
+ braille = oldbraille;
+
+ int currwrong;
+ string wrongpin;
+ // check result
+ int* wrongpins = buttonarr.wrongPins(braille, currletter);
+ int test = 1;
+ while(test == 1) {
+ wrongpin = "SYour answer is incorrect. Buttons";
+ for (int j = 1; j < wrongpins[0]; j++) { // get what pins are wrong
+ currwrong = wrongpins[j];
+ 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;
+ }
+ }
+ if (wrongpins[0] > 1) {
+ 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
+
+ sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(),
+ !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress());
+
+ // wait for input
+ while (strcmp(braille, "111111") == 0) {
+ sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(),
+ !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress());
+ }
+
+ // while buttons have not been released
+ int oldsum = 0;
+ int sum = 0;
+ while ((strcmp(braille, "111111") != 0) && (oldsum <= sum)) {
+ oldbraille = braille;
+ oldsum = sum;
+ sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(),
+ !button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress());
+ sum = button1.getPress() + button2.getPress() + button3.getPress() + button4.getPress()
+ + button5.getPress() + button6.getPress();
+ }
+
+ // check result
+ wrongpins = buttonarr.wrongPins(braille, currletter);
+ } else {
+ test = 0;
+ myTTS.speakf("SGood job!\r");
+ myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
+ }
+ }
+
+ }*/
+
// WORD CODE
// WORD COUNTER
@@ -188,7 +336,6 @@
// check what letters were wrong
// give wrong letters - correct spelling is...
- //SETTING UP SERVOS TO RELEASE FOR TYPING MODE FREEZES THE CODE
buttonarr.setup(); //Reset servos so that buttons are up for typing mode
button1.setMode(1);
@@ -200,10 +347,7 @@
string currword;
int wordsize = sizeof(word)/sizeof(word[0]);
- //int wordlength;
- //char* braille;
- //char* oldbraille;
-
+
//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
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
myTTS.ready(); //ready waits for speech to finish from last command with a ":" response
@@ -212,7 +356,7 @@
for(int i = 0; i < wordsize; i++) { //iterate through the word array
currword = word[i];
char currword1[3];
-
+
string presspin = "To type the word ";
presspin = presspin + word[i];
presspin = presspin + ", type letters ";
@@ -252,7 +396,6 @@
sprintf(braille, "%d%d%d%d%d%d", !button1.getPress(), !button2.getPress(),
!button3.getPress(), !button4.getPress(), !button5.getPress(), !button6.getPress());
}
- //pc.printf("reached");
// while buttons have not been released
int oldsum = 0;
