hi

Dependencies:   microbit

Revision:
1:52a1fd1e7193
Parent:
0:efa5691654d7
--- a/main.cpp	Sun Mar 03 09:19:54 2019 +0000
+++ b/main.cpp	Mon Mar 04 22:54:07 2019 +0000
@@ -1,68 +1,115 @@
 #include "MicroBit.h"
-//#include "binTree.h"
-
+#include "binTree.h"
+#include <string>
 MicroBit uBit;
 
-uint64_t reading;
+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)
     {
-        MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_DIGITAL);
+        
     
         value = P0.getDigitalValue();
+        //uBit.display.scroll(value);
     
-        reading = system_timer_current_time();
-        read1 = uBit.systemTime();
-        while(P0.getDigitalValue() == 1)
-        {
-           BP = true; 
-        }
-        read1 =  uBit.systemTime() - read1;  
-        while (value == 1)
-        {
-          //  uBit.display.scroll("read");
-           // read = system_timer_current_time() - reading;
-            if (1 > 0 && 1 < 500)
+       // reading = system_timer_current_time();
+        //read1 = uBit.systemTime();
+
+        if (value == 1) {
+            timePressed = system_timer_current_time();
+            BP = true;
+            while (value == 1)
             {
-                //shows a dot on the screen
-                uBit.display.scroll("dot");
+            //uBit.display.scroll("Run");
+            value = P0.getDigitalValue();
+           
             }
-            //if button is held down for a brief amount of time
-            else if (1 > 500 )
-            {
-            //shows a dash on screen
-                uBit.display.scroll("dash");
-            }
-            //if button held down for a longer time
-            /*else if (timepressed > 1500)
-            {
-                //displays stop along the screen
-                uBit.display.scroll("STOP");
-                //sets mcode as false so buttons stop running
-                mcode = false;
-            }
-            */
-            value = 0;
         }
         
         
-
-    
-        
+        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;
+              }
+              
     }
-    release_fiber();
-    
+     
+}
 
-}
-    
-     
\ No newline at end of file