4180 Morse / Mbed 2 deprecated morseCode_1_1

Dependencies:   mbed 4DGL-uLCD-SE

Fork of morseCode_1 by 4180 Morse

Files at this revision

API Documentation at this revision

Comitter:
Jeco13
Date:
Tue May 01 17:32:44 2018 +0000
Parent:
8:78b057dd6da4
Commit message:
*Commented "cout" on lines 390 & 402 in the header file.; *Commented out "Text_to_morse()" function calls on lines 122, 129, 130, & 131 in main().c.

Changed in this revision

Header_file.h 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
diff -r 78b057dd6da4 -r 3c1acc87b80c Header_file.h
--- a/Header_file.h	Tue May 01 16:42:40 2018 +0000
+++ b/Header_file.h	Tue May 01 17:32:44 2018 +0000
@@ -5,9 +5,9 @@
 
 AnalogOut speaker(p18);
 DigitalOut led(p8);
-DigitalOut myled(LED1);
-DigitalOut testled(LED2);
-DigitalOut otherled(LED3);
+DigitalOut led3(LED3); //blinks for Dash()
+DigitalOut led2(LED2);  //blinks for Dot()
+DigitalOut otherled(LED4);
 uLCD_4DGL uLCD(p28, p27, p29); // create a global uLCD object
 
 
@@ -15,9 +15,9 @@
     //turn on speaker for 0.5s.
     //turn on led for 0.5s.
     //turn off speaker & led.
-    testled = 1;
+    led2 = 1;
     wait(0.5);
-    testled = 0;
+    led2 = 0;
     wait(0.5);
 }
 
@@ -25,9 +25,9 @@
     //turn on speaker for 1s.
     //turn on led for 1s.
     //turn off speaker & led.
-    myled = 1;
+    led3 = 1;
     wait(1.0);
-    myled = 0;
+    led3 = 0;
     wait(0.5);
 }
 
@@ -162,14 +162,14 @@
     }
     else if(input_char == 'o'|| input_char == 'O'){
         //uLCD.printf("o\n");
-        //testled = 1;
+        //led2 = 1;
         dash();
         //wait(2);
         dash();
         //wait(w);
         dash();
         //wait(w);
-        //testled = 0;
+        //led2 = 0;
     }
     else if(input_char == 'p'||input_char == 'P'){
         //uLCD.printf("p\n");
@@ -387,7 +387,7 @@
         return * rootNode;
     }
     else{
-        cout << returnvalue(rootNode) << "return root \n" << returnvalue(rootNode->dot) << " return dot" << endl;
+        //cout << returnvalue(rootNode) << "return root \n" << returnvalue(rootNode->dot) << " return dot" << endl;
         rootNode = rootNode->dot;
         return *rootNode;
     }
@@ -399,7 +399,7 @@
         return * rootNode;
     }
     else{
-        cout << returnvalue(rootNode) << "return root \n" << returnvalue(rootNode->dash) << " return dash" << endl;
+        //cout << returnvalue(rootNode) << "return root \n" << returnvalue(rootNode->dash) << " return dash" << endl;
         rootNode = rootNode->dash;
         return * rootNode;
     }
diff -r 78b057dd6da4 -r 3c1acc87b80c main.cpp
--- 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);
     }
 }