Text_to_morse function written

Dependencies:   mbed 4DGL-uLCD-SE

Fork of morseCode_1 by 4180 Morse

Revision:
9:3c1acc87b80c
Parent:
8:78b057dd6da4
--- a/main.cpp	Tue May 01 16:42:40 2018 +0000
+++ b/main.cpp	Tue May 01 17:32:44 2018 +0000
@@ -10,6 +10,31 @@
 //Traverse the tree using telegraph key
 //Make menus/UI look pretty
 
+//
+RawSerial  pc(USBTX, USBRX);//pc serial out
+Serial  dev(p13,p14);//serial text input from bluetooth module
+DigitalOut led1(LED1);  //For spacing between character. Denotes the end of a character
+
+
+//Variables
+char string_input[20];
+
+void dev_recv() //Funtion that reads in text from bluetooth, and calls the text to morse conversion function
+{
+    if(dev.readable()){             //scan in inout string
+            dev.scanf("%s",string_input);
+    }
+    
+    int string_length = strlen(string_input);
+    
+    for(int i = 0; i<string_length; i++) { //call Text_to_morse() function on each character of input string
+        wait(1.0);
+        Text_to_morse(string_input[i]);
+        led1 = !led1;   //blink to denote end of current character output
+        wait(0.1);
+        led1 = !led1;
+    }
+}
 
 
 //Part 1
@@ -18,6 +43,9 @@
 
 int main() {
     
+    //Function call for bluetooth text input
+    dev.attach(&dev_recv, Serial::RxIrq); //calls text_to_morse function on bluetooth text inputs
+    
     //Variable word list for the game portion
     //Feel free to add words, just update the array size
     string wordlist[20] = {"Dog","Cat","Car","Tree","Star","Radio","Tea","Book","Hello","Bank","Bird","Bus","Red","Green","Blue","Coat","Dress","Shirt","Egg","Pear"};
@@ -91,16 +119,16 @@
     string newString = "YYZ";
     
     for (int i = 0; i < newString.length(); i++){
-        Text_to_morse(newString[i]);
+        //Text_to_morse(newString[i]);
     }
     
     char schar = 's';
     char ochar = 'o';
     while(1) {
         uLCD.printf("do this\n");
-        Text_to_morse(schar);
-        Text_to_morse(ochar);
-        Text_to_morse(schar);
+        //Text_to_morse(schar);
+//        Text_to_morse(ochar);
+//        Text_to_morse(schar);
         wait(0.5);
     }
 }