hi

Dependencies:   microbit

Files at this revision

API Documentation at this revision

Comitter:
schizzlewizzle
Date:
Mon Mar 04 22:54:07 2019 +0000
Parent:
0:efa5691654d7
Commit message:
hi

Changed in this revision

binTree.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
microbit.lib Show annotated file Show diff for this revision Revisions of this file
diff -r efa5691654d7 -r 52a1fd1e7193 binTree.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/binTree.cpp	Mon Mar 04 22:54:07 2019 +0000
@@ -0,0 +1,86 @@
+#include "binTree.h"
+#include <string.h>
+
+using std::string;
+//constructor that makes root a new node for insertion.
+binTree::binTree() {
+    root = new node;
+//root.dot = NULL;
+//root.dash = NULL;
+    
+
+
+}
+
+
+//Function to fill the tree, public facing as developers don't need to know root.
+void binTree::insert(char inputC, string morse) {
+
+    node *r = this->root;
+    
+    
+    //loop going through length of morse and seeing if dash or dot for where to add new nodes.
+    for (int i = 0; i < morse.length(); i++) {
+    // assert(r);
+        if (morse[i] == '-') {
+            if (r->dash == NULL) {
+                r->dash = new node;
+            }
+        r = r->dash;
+        }
+        else if (morse[i] == '.') {
+            if (r->dot == NULL) {
+                r->dot = new node;
+            }
+        r = r->dot;
+        }
+    
+    
+        }
+    insert(inputC, morse, r);
+    
+    //else {
+    
+    //}
+}
+
+
+//sets char and string in the specific node designated at r.
+void binTree::insert(char inputC, string morse, node * r) {
+
+    r->inputC = inputC;
+    r->morse = morse;
+}
+
+//search function that traverses down the tree till it finds the coresponding morse, then returns the alphabetical value stored in that node.
+
+char binTree::tFind(node * r, string morse)
+{
+    if (r != NULL){
+        for (int i = 0; i < morse.length(); i++) {
+//assert(r);
+            if (morse[i] == '-') {
+    //these if statements check to see whether there's actually any data at that node, and if not, then it exits the function.
+                if (r->dash == NULL){
+                    exit(0);
+                }
+                else {
+                    r = r->dash;
+                }
+
+            }
+            else if (morse[i] == '.') {
+                if (r->dot == NULL){
+            }
+                else {
+                    r = r->dot;
+                    }
+
+            }
+        }
+    }
+    else{
+    
+    }
+    return r->inputC;
+}
\ No newline at end of file
diff -r efa5691654d7 -r 52a1fd1e7193 main.cpp
--- 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
diff -r efa5691654d7 -r 52a1fd1e7193 microbit.lib
--- a/microbit.lib	Sun Mar 03 09:19:54 2019 +0000
+++ b/microbit.lib	Mon Mar 04 22:54:07 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/Lancaster-University/code/microbit/#4b89e7e3494f
+https://os.mbed.com/users/schizzlewizzle/code/microbit/#470dd4b66b6f