hi
main.cpp
- Committer:
- schizzlewizzle
- Date:
- 2019-03-04
- Revision:
- 1:52a1fd1e7193
- Parent:
- 0:efa5691654d7
File content as of revision 1:52a1fd1e7193:
#include "MicroBit.h" #include "binTree.h" #include <string> MicroBit uBit; uint64_t reading, howLongSent; bool running = false; int value = 0; bool BP = false; long timePressed; int read1; string inputMorse; bool stopBit; char outPut; using std::string; void insertMorseChar(binTree* tree){ tree->insert('A', ".-"); tree->insert('B', "-..."); tree->insert('C', "-.-."); tree->insert('D', "-.."); tree->insert('E', "."); tree->insert('F', "..-."); tree->insert('G', "--."); tree->insert('H', "...."); tree->insert('I', ".."); tree->insert('J', ".---"); tree->insert('K', "-.-"); tree->insert('L', ".-.."); tree->insert('M', "--"); tree->insert('N', "-."); tree->insert('O', "---"); tree->insert('P', ".--."); tree->insert('Q', "--.-"); tree->insert('R', ".-."); tree->insert('S', "..."); tree->insert('T', "-"); tree->insert('U', "..-"); tree->insert('V', "...-"); tree->insert('W', ".--"); tree->insert('X', "-..-"); tree->insert('Y', "-.--"); tree->insert('Z', "--.."); tree->insert('0', "-----"); tree->insert('1', ".----"); tree->insert('2', "..---"); tree->insert('3', "...--"); tree->insert('4', "....-"); tree->insert('5', "....."); tree->insert('6', "-...."); tree->insert('7', "--..."); tree->insert('8', "---.."); tree->insert('9', "----."); } int main() { uBit.init(); binTree* tree = new binTree(); insertMorseChar(tree); MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_DIGITAL); uBit.display.clear(); while(1) { value = P0.getDigitalValue(); //uBit.display.scroll(value); // reading = system_timer_current_time(); //read1 = uBit.systemTime(); if (value == 1) { timePressed = system_timer_current_time(); BP = true; while (value == 1) { //uBit.display.scroll("Run"); value = P0.getDigitalValue(); } } if(BP == true){ //uBit.display.scroll("2"); howLongSent = system_timer_current_time() - timePressed; //uBit.display.scroll(howLongSent); if(howLongSent > 0 && howLongSent < 500){ uBit.display.scroll("."); inputMorse += "."; }else if(howLongSent > 500 && howLongSent < 1000){ uBit.display.scroll("-"); inputMorse += "-"; //string inputMorse = inputMorse + "-"; }else if(howLongSent > 1000){ uBit.display.scroll("stop"); stopBit = true; } } BP = false; if(stopBit == true){ tree->tFind(tree->root, inputMorse); stopBit = false; } } }