Liam McNamara / MicroBitReceiver

Dependencies:   microbit

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "MicroBit.h"
00002 #include "binTree.h"
00003 #include <string>
00004 MicroBit uBit;
00005 
00006 uint64_t reading, howLongSent;
00007 bool running = false;
00008 int value = 0;
00009 bool BP = false;
00010 long timePressed;
00011 int read1;
00012 string inputMorse;
00013 bool stopBit;
00014 char outPut;
00015 
00016 using std::string;
00017 
00018 
00019 void insertMorseChar(binTree* tree){
00020     tree->insert('A', ".-");
00021     tree->insert('B', "-...");
00022     tree->insert('C', "-.-.");
00023     tree->insert('D', "-..");
00024     tree->insert('E', ".");
00025     tree->insert('F', "..-.");
00026     tree->insert('G', "--.");
00027     tree->insert('H', "....");
00028     tree->insert('I', "..");
00029     tree->insert('J', ".---");
00030     tree->insert('K', "-.-");
00031     tree->insert('L', ".-..");
00032     tree->insert('M', "--");
00033     tree->insert('N', "-.");
00034     tree->insert('O', "---");
00035     tree->insert('P', ".--.");
00036     tree->insert('Q', "--.-");
00037     tree->insert('R', ".-.");
00038     tree->insert('S', "...");
00039     tree->insert('T', "-");
00040     tree->insert('U', "..-");
00041     tree->insert('V', "...-");
00042     tree->insert('W', ".--");
00043     tree->insert('X', "-..-");
00044     tree->insert('Y', "-.--");
00045     tree->insert('Z', "--..");
00046     tree->insert('0', "-----");
00047     tree->insert('1', ".----");
00048     tree->insert('2', "..---");
00049     tree->insert('3', "...--");
00050     tree->insert('4', "....-");
00051     tree->insert('5', ".....");
00052     tree->insert('6', "-....");
00053     tree->insert('7', "--...");
00054     tree->insert('8', "---..");
00055     tree->insert('9', "----.");
00056 }
00057 
00058 int main()
00059 {   
00060     
00061     
00062     uBit.init();
00063     binTree* tree = new binTree();
00064     insertMorseChar(tree);
00065     MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_DIGITAL);
00066     uBit.display.clear();
00067     while(1)
00068     {
00069         
00070     
00071         value = P0.getDigitalValue();
00072         //uBit.display.scroll(value);
00073     
00074        // reading = system_timer_current_time();
00075         //read1 = uBit.systemTime();
00076 
00077         if (value == 1) {
00078             timePressed = system_timer_current_time();
00079             BP = true;
00080             while (value == 1)
00081             {
00082             //uBit.display.scroll("Run");
00083             value = P0.getDigitalValue();
00084            
00085             }
00086         }
00087         
00088         
00089         if(BP == true){
00090             //uBit.display.scroll("2");
00091             howLongSent = system_timer_current_time() - timePressed;
00092            //uBit.display.scroll(howLongSent);
00093             if(howLongSent > 0 && howLongSent < 500){
00094                 uBit.display.scroll(".");
00095                 inputMorse += ".";
00096                 
00097             }else if(howLongSent > 500 && howLongSent < 1000){
00098                 uBit.display.scroll("-");
00099                 inputMorse += "-";
00100                 //string inputMorse = inputMorse + "-";
00101             }else if(howLongSent > 1000){
00102                 uBit.display.scroll("stop");
00103                 stopBit = true;
00104             }
00105         }
00106         BP = false;
00107           if(stopBit == true){
00108               tree->tFind(tree->root, inputMorse);
00109               stopBit = false;
00110               }
00111               
00112     }
00113      
00114 }
00115