hi
main.cpp@1:52a1fd1e7193, 2019-03-04 (annotated)
- Committer:
- schizzlewizzle
- Date:
- Mon Mar 04 22:54:07 2019 +0000
- Revision:
- 1:52a1fd1e7193
- Parent:
- 0:efa5691654d7
hi
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bvnoake | 0:efa5691654d7 | 1 | #include "MicroBit.h" |
schizzlewizzle | 1:52a1fd1e7193 | 2 | #include "binTree.h" |
schizzlewizzle | 1:52a1fd1e7193 | 3 | #include <string> |
bvnoake | 0:efa5691654d7 | 4 | MicroBit uBit; |
bvnoake | 0:efa5691654d7 | 5 | |
schizzlewizzle | 1:52a1fd1e7193 | 6 | uint64_t reading, howLongSent; |
bvnoake | 0:efa5691654d7 | 7 | bool running = false; |
bvnoake | 0:efa5691654d7 | 8 | int value = 0; |
bvnoake | 0:efa5691654d7 | 9 | bool BP = false; |
schizzlewizzle | 1:52a1fd1e7193 | 10 | long timePressed; |
bvnoake | 0:efa5691654d7 | 11 | int read1; |
schizzlewizzle | 1:52a1fd1e7193 | 12 | string inputMorse; |
schizzlewizzle | 1:52a1fd1e7193 | 13 | bool stopBit; |
schizzlewizzle | 1:52a1fd1e7193 | 14 | char outPut; |
bvnoake | 0:efa5691654d7 | 15 | |
schizzlewizzle | 1:52a1fd1e7193 | 16 | using std::string; |
schizzlewizzle | 1:52a1fd1e7193 | 17 | |
schizzlewizzle | 1:52a1fd1e7193 | 18 | |
schizzlewizzle | 1:52a1fd1e7193 | 19 | void insertMorseChar(binTree* tree){ |
schizzlewizzle | 1:52a1fd1e7193 | 20 | tree->insert('A', ".-"); |
schizzlewizzle | 1:52a1fd1e7193 | 21 | tree->insert('B', "-..."); |
schizzlewizzle | 1:52a1fd1e7193 | 22 | tree->insert('C', "-.-."); |
schizzlewizzle | 1:52a1fd1e7193 | 23 | tree->insert('D', "-.."); |
schizzlewizzle | 1:52a1fd1e7193 | 24 | tree->insert('E', "."); |
schizzlewizzle | 1:52a1fd1e7193 | 25 | tree->insert('F', "..-."); |
schizzlewizzle | 1:52a1fd1e7193 | 26 | tree->insert('G', "--."); |
schizzlewizzle | 1:52a1fd1e7193 | 27 | tree->insert('H', "...."); |
schizzlewizzle | 1:52a1fd1e7193 | 28 | tree->insert('I', ".."); |
schizzlewizzle | 1:52a1fd1e7193 | 29 | tree->insert('J', ".---"); |
schizzlewizzle | 1:52a1fd1e7193 | 30 | tree->insert('K', "-.-"); |
schizzlewizzle | 1:52a1fd1e7193 | 31 | tree->insert('L', ".-.."); |
schizzlewizzle | 1:52a1fd1e7193 | 32 | tree->insert('M', "--"); |
schizzlewizzle | 1:52a1fd1e7193 | 33 | tree->insert('N', "-."); |
schizzlewizzle | 1:52a1fd1e7193 | 34 | tree->insert('O', "---"); |
schizzlewizzle | 1:52a1fd1e7193 | 35 | tree->insert('P', ".--."); |
schizzlewizzle | 1:52a1fd1e7193 | 36 | tree->insert('Q', "--.-"); |
schizzlewizzle | 1:52a1fd1e7193 | 37 | tree->insert('R', ".-."); |
schizzlewizzle | 1:52a1fd1e7193 | 38 | tree->insert('S', "..."); |
schizzlewizzle | 1:52a1fd1e7193 | 39 | tree->insert('T', "-"); |
schizzlewizzle | 1:52a1fd1e7193 | 40 | tree->insert('U', "..-"); |
schizzlewizzle | 1:52a1fd1e7193 | 41 | tree->insert('V', "...-"); |
schizzlewizzle | 1:52a1fd1e7193 | 42 | tree->insert('W', ".--"); |
schizzlewizzle | 1:52a1fd1e7193 | 43 | tree->insert('X', "-..-"); |
schizzlewizzle | 1:52a1fd1e7193 | 44 | tree->insert('Y', "-.--"); |
schizzlewizzle | 1:52a1fd1e7193 | 45 | tree->insert('Z', "--.."); |
schizzlewizzle | 1:52a1fd1e7193 | 46 | tree->insert('0', "-----"); |
schizzlewizzle | 1:52a1fd1e7193 | 47 | tree->insert('1', ".----"); |
schizzlewizzle | 1:52a1fd1e7193 | 48 | tree->insert('2', "..---"); |
schizzlewizzle | 1:52a1fd1e7193 | 49 | tree->insert('3', "...--"); |
schizzlewizzle | 1:52a1fd1e7193 | 50 | tree->insert('4', "....-"); |
schizzlewizzle | 1:52a1fd1e7193 | 51 | tree->insert('5', "....."); |
schizzlewizzle | 1:52a1fd1e7193 | 52 | tree->insert('6', "-...."); |
schizzlewizzle | 1:52a1fd1e7193 | 53 | tree->insert('7', "--..."); |
schizzlewizzle | 1:52a1fd1e7193 | 54 | tree->insert('8', "---.."); |
schizzlewizzle | 1:52a1fd1e7193 | 55 | tree->insert('9', "----."); |
schizzlewizzle | 1:52a1fd1e7193 | 56 | } |
bvnoake | 0:efa5691654d7 | 57 | |
bvnoake | 0:efa5691654d7 | 58 | int main() |
schizzlewizzle | 1:52a1fd1e7193 | 59 | { |
schizzlewizzle | 1:52a1fd1e7193 | 60 | |
bvnoake | 0:efa5691654d7 | 61 | |
bvnoake | 0:efa5691654d7 | 62 | uBit.init(); |
schizzlewizzle | 1:52a1fd1e7193 | 63 | binTree* tree = new binTree(); |
schizzlewizzle | 1:52a1fd1e7193 | 64 | insertMorseChar(tree); |
schizzlewizzle | 1:52a1fd1e7193 | 65 | MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_DIGITAL); |
schizzlewizzle | 1:52a1fd1e7193 | 66 | uBit.display.clear(); |
bvnoake | 0:efa5691654d7 | 67 | while(1) |
bvnoake | 0:efa5691654d7 | 68 | { |
schizzlewizzle | 1:52a1fd1e7193 | 69 | |
bvnoake | 0:efa5691654d7 | 70 | |
bvnoake | 0:efa5691654d7 | 71 | value = P0.getDigitalValue(); |
schizzlewizzle | 1:52a1fd1e7193 | 72 | //uBit.display.scroll(value); |
bvnoake | 0:efa5691654d7 | 73 | |
schizzlewizzle | 1:52a1fd1e7193 | 74 | // reading = system_timer_current_time(); |
schizzlewizzle | 1:52a1fd1e7193 | 75 | //read1 = uBit.systemTime(); |
schizzlewizzle | 1:52a1fd1e7193 | 76 | |
schizzlewizzle | 1:52a1fd1e7193 | 77 | if (value == 1) { |
schizzlewizzle | 1:52a1fd1e7193 | 78 | timePressed = system_timer_current_time(); |
schizzlewizzle | 1:52a1fd1e7193 | 79 | BP = true; |
schizzlewizzle | 1:52a1fd1e7193 | 80 | while (value == 1) |
bvnoake | 0:efa5691654d7 | 81 | { |
schizzlewizzle | 1:52a1fd1e7193 | 82 | //uBit.display.scroll("Run"); |
schizzlewizzle | 1:52a1fd1e7193 | 83 | value = P0.getDigitalValue(); |
schizzlewizzle | 1:52a1fd1e7193 | 84 | |
bvnoake | 0:efa5691654d7 | 85 | } |
bvnoake | 0:efa5691654d7 | 86 | } |
bvnoake | 0:efa5691654d7 | 87 | |
bvnoake | 0:efa5691654d7 | 88 | |
schizzlewizzle | 1:52a1fd1e7193 | 89 | if(BP == true){ |
schizzlewizzle | 1:52a1fd1e7193 | 90 | //uBit.display.scroll("2"); |
schizzlewizzle | 1:52a1fd1e7193 | 91 | howLongSent = system_timer_current_time() - timePressed; |
schizzlewizzle | 1:52a1fd1e7193 | 92 | //uBit.display.scroll(howLongSent); |
schizzlewizzle | 1:52a1fd1e7193 | 93 | if(howLongSent > 0 && howLongSent < 500){ |
schizzlewizzle | 1:52a1fd1e7193 | 94 | uBit.display.scroll("."); |
schizzlewizzle | 1:52a1fd1e7193 | 95 | inputMorse += "."; |
schizzlewizzle | 1:52a1fd1e7193 | 96 | |
schizzlewizzle | 1:52a1fd1e7193 | 97 | }else if(howLongSent > 500 && howLongSent < 1000){ |
schizzlewizzle | 1:52a1fd1e7193 | 98 | uBit.display.scroll("-"); |
schizzlewizzle | 1:52a1fd1e7193 | 99 | inputMorse += "-"; |
schizzlewizzle | 1:52a1fd1e7193 | 100 | //string inputMorse = inputMorse + "-"; |
schizzlewizzle | 1:52a1fd1e7193 | 101 | }else if(howLongSent > 1000){ |
schizzlewizzle | 1:52a1fd1e7193 | 102 | uBit.display.scroll("stop"); |
schizzlewizzle | 1:52a1fd1e7193 | 103 | stopBit = true; |
schizzlewizzle | 1:52a1fd1e7193 | 104 | } |
schizzlewizzle | 1:52a1fd1e7193 | 105 | } |
schizzlewizzle | 1:52a1fd1e7193 | 106 | BP = false; |
schizzlewizzle | 1:52a1fd1e7193 | 107 | if(stopBit == true){ |
schizzlewizzle | 1:52a1fd1e7193 | 108 | tree->tFind(tree->root, inputMorse); |
schizzlewizzle | 1:52a1fd1e7193 | 109 | stopBit = false; |
schizzlewizzle | 1:52a1fd1e7193 | 110 | } |
schizzlewizzle | 1:52a1fd1e7193 | 111 | |
bvnoake | 0:efa5691654d7 | 112 | } |
schizzlewizzle | 1:52a1fd1e7193 | 113 | |
schizzlewizzle | 1:52a1fd1e7193 | 114 | } |
bvnoake | 0:efa5691654d7 | 115 |