Working read code with mode button
Dependencies: SDFileSystem emic2 mbed-rtos mbed
Fork of BAT_senior_design_Testnew by
buttonArray.cpp@1:f3d363ca2343, 2017-12-04 (annotated)
- Committer:
- nnguyen45
- Date:
- Mon Dec 04 20:14:24 2017 +0000
- Revision:
- 1:f3d363ca2343
- Parent:
- 0:5887cb744114
- Child:
- 42:44a898adef26
Updated button array to include almost all letters
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nnguyen45 | 0:5887cb744114 | 1 | #include "mbed.h" |
nnguyen45 | 0:5887cb744114 | 2 | #include "buttonArray.h" |
nnguyen45 | 0:5887cb744114 | 3 | |
nnguyen45 | 0:5887cb744114 | 4 | // buttonArray constructor |
nnguyen45 | 0:5887cb744114 | 5 | buttonArray::buttonArray(button b1, button b2, button b3, button b4, button b5, button b6) |
nnguyen45 | 0:5887cb744114 | 6 | : button1(b1), button2(b2), button3(b3), button4(b4), button5(b5), button6(b6) {} |
nnguyen45 | 0:5887cb744114 | 7 | |
nnguyen45 | 0:5887cb744114 | 8 | // FUNCTIONS |
nnguyen45 | 0:5887cb744114 | 9 | |
nnguyen45 | 0:5887cb744114 | 10 | // map input braille to ascii |
nnguyen45 | 0:5887cb744114 | 11 | // braille respresentation here - https://en.wikipedia.org/wiki/Braille_ASCII |
nnguyen45 | 0:5887cb744114 | 12 | char buttonArray::checkVal(char* braille) |
nnguyen45 | 0:5887cb744114 | 13 | { |
nnguyen45 | 0:5887cb744114 | 14 | char val = 'K'; |
nnguyen45 | 0:5887cb744114 | 15 | if (strcmp(braille, "000000") == 0) val = 'X'; |
nnguyen45 | 0:5887cb744114 | 16 | if (strcmp(braille, "011111") == 0) val = 'A'; |
nnguyen45 | 0:5887cb744114 | 17 | if (strcmp(braille, "001111") == 0) val = 'B'; |
nnguyen45 | 0:5887cb744114 | 18 | if (strcmp(braille, "011011") == 0) val = 'C'; |
nnguyen45 | 0:5887cb744114 | 19 | if (strcmp(braille, "011001") == 0) val = 'D'; |
nnguyen45 | 0:5887cb744114 | 20 | if (strcmp(braille, "011101") == 0) val = 'E'; |
nnguyen45 | 0:5887cb744114 | 21 | if (strcmp(braille, "001011") == 0) val = 'F'; |
nnguyen45 | 0:5887cb744114 | 22 | if (strcmp(braille, "001001") == 0) val = 'G'; |
nnguyen45 | 0:5887cb744114 | 23 | if (strcmp(braille, "001101") == 0) val = 'H'; |
nnguyen45 | 1:f3d363ca2343 | 24 | if (strcmp(braille, "101011") == 0) val = 'I'; |
nnguyen45 | 0:5887cb744114 | 25 | if (strcmp(braille, "101001") == 0) val = 'J'; |
nnguyen45 | 1:f3d363ca2343 | 26 | //if (strcmp(braille, "011111") == 0) val = 'K'; |
nnguyen45 | 1:f3d363ca2343 | 27 | if (strcmp(braille, "000111") == 0) val = 'L'; |
nnguyen45 | 0:5887cb744114 | 28 | if (strcmp(braille, "010011") == 0) val = 'M'; |
nnguyen45 | 1:f3d363ca2343 | 29 | if (strcmp(braille, "010001") == 0) val = 'N'; |
nnguyen45 | 0:5887cb744114 | 30 | if (strcmp(braille, "010101") == 0) val = 'O'; |
nnguyen45 | 1:f3d363ca2343 | 31 | if (strcmp(braille, "000011") == 0) val = 'P'; |
nnguyen45 | 1:f3d363ca2343 | 32 | if (strcmp(braille, "000001") == 0) val = 'Q'; |
nnguyen45 | 1:f3d363ca2343 | 33 | if (strcmp(braille, "000101") == 0) val = 'R'; |
nnguyen45 | 1:f3d363ca2343 | 34 | if (strcmp(braille, "100011") == 0) val = 'S'; |
nnguyen45 | 1:f3d363ca2343 | 35 | if (strcmp(braille, "100001") == 0) val = 'T'; |
nnguyen45 | 1:f3d363ca2343 | 36 | if (strcmp(braille, "010110") == 0) val = 'U'; |
nnguyen45 | 1:f3d363ca2343 | 37 | if (strcmp(braille, "000110") == 0) val = 'V'; |
nnguyen45 | 1:f3d363ca2343 | 38 | if (strcmp(braille, "101000") == 0) val = 'W'; |
nnguyen45 | 1:f3d363ca2343 | 39 | //if (strcmp(braille, "010010") == 0) val = 'X'; |
nnguyen45 | 1:f3d363ca2343 | 40 | if (strcmp(braille, "010000") == 0) val = 'Y'; |
nnguyen45 | 1:f3d363ca2343 | 41 | //if (strcmp(braille, "010100") == 0) val = 'Z'; |
nnguyen45 | 0:5887cb744114 | 42 | // check if reset |
nnguyen45 | 0:5887cb744114 | 43 | if (strcmp(braille, "111111") == 0) val = 'Z'; |
nnguyen45 | 0:5887cb744114 | 44 | return val; |
nnguyen45 | 0:5887cb744114 | 45 | } |
nnguyen45 | 0:5887cb744114 | 46 | |
nnguyen45 | 0:5887cb744114 | 47 | // get braille represention of char |
nnguyen45 | 0:5887cb744114 | 48 | char* buttonArray::getBraille(char val) |
nnguyen45 | 0:5887cb744114 | 49 | { |
nnguyen45 | 0:5887cb744114 | 50 | char* braille; |
nnguyen45 | 0:5887cb744114 | 51 | if (val == 'A') braille = "011111"; |
nnguyen45 | 0:5887cb744114 | 52 | if (val == 'X') braille = "000000"; |
nnguyen45 | 0:5887cb744114 | 53 | if (val == 'Z') braille = "111111"; |
nnguyen45 | 0:5887cb744114 | 54 | if (val == 'M') braille = "010011"; |
nnguyen45 | 0:5887cb744114 | 55 | if (val == 'O') braille = "010101"; |
nnguyen45 | 0:5887cb744114 | 56 | if (val == 'K') braille = "100000"; |
nnguyen45 | 0:5887cb744114 | 57 | // check if reset |
nnguyen45 | 0:5887cb744114 | 58 | if (val == ' ') braille = "111111"; |
nnguyen45 | 0:5887cb744114 | 59 | return braille; |
nnguyen45 | 0:5887cb744114 | 60 | } |
nnguyen45 | 0:5887cb744114 | 61 | |
nnguyen45 | 0:5887cb744114 | 62 | // return an array of which pins need to be up |
nnguyen45 | 0:5887cb744114 | 63 | int* buttonArray::pinsUp(char val) |
nnguyen45 | 0:5887cb744114 | 64 | { |
nnguyen45 | 0:5887cb744114 | 65 | int* pinsup; |
nnguyen45 | 0:5887cb744114 | 66 | char* braille = getBraille(val); |
nnguyen45 | 0:5887cb744114 | 67 | int j = 1; |
nnguyen45 | 0:5887cb744114 | 68 | for (int i = 0; i < 6; i++) { |
nnguyen45 | 0:5887cb744114 | 69 | if (braille[i] == '0') { |
nnguyen45 | 0:5887cb744114 | 70 | pinsup[j] = i+1; |
nnguyen45 | 0:5887cb744114 | 71 | j++; |
nnguyen45 | 0:5887cb744114 | 72 | } |
nnguyen45 | 0:5887cb744114 | 73 | } |
nnguyen45 | 0:5887cb744114 | 74 | // record size of array in the first element |
nnguyen45 | 0:5887cb744114 | 75 | pinsup[0] = j; |
nnguyen45 | 0:5887cb744114 | 76 | return pinsup; |
nnguyen45 | 0:5887cb744114 | 77 | } |
nnguyen45 | 0:5887cb744114 | 78 | |
nnguyen45 | 0:5887cb744114 | 79 | // return feedback on which pins need to be corrected |
nnguyen45 | 0:5887cb744114 | 80 | // takes in current and actual char as input and returns status of each char |
nnguyen45 | 0:5887cb744114 | 81 | int* buttonArray::wrongPins(char* inarr, char actual) |
nnguyen45 | 0:5887cb744114 | 82 | { |
nnguyen45 | 0:5887cb744114 | 83 | int* wrong; |
nnguyen45 | 0:5887cb744114 | 84 | wrong = new int[7]; |
nnguyen45 | 0:5887cb744114 | 85 | char* actarr = getBraille(actual); |
nnguyen45 | 0:5887cb744114 | 86 | int j = 1; |
nnguyen45 | 0:5887cb744114 | 87 | for (int i = 0; i < 6; i++) { |
nnguyen45 | 0:5887cb744114 | 88 | if(inarr[i] != actarr[i]) { |
nnguyen45 | 0:5887cb744114 | 89 | wrong[j] = i+1; |
nnguyen45 | 0:5887cb744114 | 90 | j++; |
nnguyen45 | 0:5887cb744114 | 91 | } |
nnguyen45 | 0:5887cb744114 | 92 | } |
nnguyen45 | 0:5887cb744114 | 93 | // record size of array in the first element |
nnguyen45 | 0:5887cb744114 | 94 | wrong[0] = j; |
nnguyen45 | 0:5887cb744114 | 95 | return wrong; |
nnguyen45 | 0:5887cb744114 | 96 | } |
nnguyen45 | 0:5887cb744114 | 97 | |
nnguyen45 | 0:5887cb744114 | 98 | // release buttons |
nnguyen45 | 0:5887cb744114 | 99 | void buttonArray::releaseButtons() |
nnguyen45 | 0:5887cb744114 | 100 | { |
nnguyen45 | 0:5887cb744114 | 101 | if (button1.getPress()) { |
nnguyen45 | 0:5887cb744114 | 102 | button1.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 103 | button1.setState(3); |
nnguyen45 | 0:5887cb744114 | 104 | button1.setPress(0); |
nnguyen45 | 0:5887cb744114 | 105 | } |
nnguyen45 | 0:5887cb744114 | 106 | if (button2.getPress()) { |
nnguyen45 | 0:5887cb744114 | 107 | button2.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 108 | button2.setState(3); |
nnguyen45 | 0:5887cb744114 | 109 | button2.setPress(0); |
nnguyen45 | 0:5887cb744114 | 110 | } |
nnguyen45 | 0:5887cb744114 | 111 | if (button3.getPress()) { |
nnguyen45 | 0:5887cb744114 | 112 | button3.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 113 | button3.setState(3); |
nnguyen45 | 0:5887cb744114 | 114 | button3.setPress(0); |
nnguyen45 | 0:5887cb744114 | 115 | } |
nnguyen45 | 0:5887cb744114 | 116 | if (button4.getPress()) { |
nnguyen45 | 0:5887cb744114 | 117 | button4.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 118 | button4.setState(3); |
nnguyen45 | 0:5887cb744114 | 119 | button4.setPress(0); |
nnguyen45 | 0:5887cb744114 | 120 | } |
nnguyen45 | 0:5887cb744114 | 121 | if (button5.getPress()) { |
nnguyen45 | 0:5887cb744114 | 122 | button5.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 123 | button5.setState(3); |
nnguyen45 | 0:5887cb744114 | 124 | button5.setPress(0); |
nnguyen45 | 0:5887cb744114 | 125 | } |
nnguyen45 | 0:5887cb744114 | 126 | if (button6.getPress()) { |
nnguyen45 | 0:5887cb744114 | 127 | button6.moveServoOut(); |
nnguyen45 | 0:5887cb744114 | 128 | button6.setState(3); |
nnguyen45 | 0:5887cb744114 | 129 | button6.setPress(0); |
nnguyen45 | 0:5887cb744114 | 130 | } |
nnguyen45 | 0:5887cb744114 | 131 | } |
nnguyen45 | 0:5887cb744114 | 132 | |
nnguyen45 | 0:5887cb744114 | 133 | void buttonArray::setup() |
nnguyen45 | 0:5887cb744114 | 134 | { |
nnguyen45 | 1:f3d363ca2343 | 135 | // servo setup function; servos begin at 30 degrees |
nnguyen45 | 0:5887cb744114 | 136 | button1.setup(); |
nnguyen45 | 0:5887cb744114 | 137 | button2.setup(); |
nnguyen45 | 0:5887cb744114 | 138 | button3.setup(); |
nnguyen45 | 0:5887cb744114 | 139 | button4.setup(); |
nnguyen45 | 0:5887cb744114 | 140 | button5.setup(); |
nnguyen45 | 0:5887cb744114 | 141 | button6.setup(); |
nnguyen45 | 0:5887cb744114 | 142 | } |