Text_to_morse function written
Dependencies: mbed 4DGL-uLCD-SE
Fork of morseCode_1 by
main.cpp@9:3c1acc87b80c, 2018-05-01 (annotated)
- Committer:
- Jeco13
- Date:
- Tue May 01 17:32:44 2018 +0000
- Revision:
- 9:3c1acc87b80c
- Parent:
- 8:78b057dd6da4
*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.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
colson | 0:4e10b6c94be9 | 1 | #include "mbed.h" |
colson | 4:62c590826ddb | 2 | #include "Header_file.h" |
colson | 4:62c590826ddb | 3 | #include <iostream> |
colson | 4:62c590826ddb | 4 | #include <string> |
colson | 4:62c590826ddb | 5 | |
colson | 6:421ece74143e | 6 | //To-do list: |
colson | 6:421ece74143e | 7 | //Bluetooth input for strings |
colson | 6:421ece74143e | 8 | //Modify dot/dash for speaker/LED output |
colson | 6:421ece74143e | 9 | //Give user output/UI for game |
colson | 6:421ece74143e | 10 | //Traverse the tree using telegraph key |
colson | 6:421ece74143e | 11 | //Make menus/UI look pretty |
colson | 5:5b86521e418c | 12 | |
Jeco13 | 9:3c1acc87b80c | 13 | // |
Jeco13 | 9:3c1acc87b80c | 14 | RawSerial pc(USBTX, USBRX);//pc serial out |
Jeco13 | 9:3c1acc87b80c | 15 | Serial dev(p13,p14);//serial text input from bluetooth module |
Jeco13 | 9:3c1acc87b80c | 16 | DigitalOut led1(LED1); //For spacing between character. Denotes the end of a character |
Jeco13 | 9:3c1acc87b80c | 17 | |
Jeco13 | 9:3c1acc87b80c | 18 | |
Jeco13 | 9:3c1acc87b80c | 19 | //Variables |
Jeco13 | 9:3c1acc87b80c | 20 | char string_input[20]; |
Jeco13 | 9:3c1acc87b80c | 21 | |
Jeco13 | 9:3c1acc87b80c | 22 | void dev_recv() //Funtion that reads in text from bluetooth, and calls the text to morse conversion function |
Jeco13 | 9:3c1acc87b80c | 23 | { |
Jeco13 | 9:3c1acc87b80c | 24 | if(dev.readable()){ //scan in inout string |
Jeco13 | 9:3c1acc87b80c | 25 | dev.scanf("%s",string_input); |
Jeco13 | 9:3c1acc87b80c | 26 | } |
Jeco13 | 9:3c1acc87b80c | 27 | |
Jeco13 | 9:3c1acc87b80c | 28 | int string_length = strlen(string_input); |
Jeco13 | 9:3c1acc87b80c | 29 | |
Jeco13 | 9:3c1acc87b80c | 30 | for(int i = 0; i<string_length; i++) { //call Text_to_morse() function on each character of input string |
Jeco13 | 9:3c1acc87b80c | 31 | wait(1.0); |
Jeco13 | 9:3c1acc87b80c | 32 | Text_to_morse(string_input[i]); |
Jeco13 | 9:3c1acc87b80c | 33 | led1 = !led1; //blink to denote end of current character output |
Jeco13 | 9:3c1acc87b80c | 34 | wait(0.1); |
Jeco13 | 9:3c1acc87b80c | 35 | led1 = !led1; |
Jeco13 | 9:3c1acc87b80c | 36 | } |
Jeco13 | 9:3c1acc87b80c | 37 | } |
colson | 5:5b86521e418c | 38 | |
colson | 5:5b86521e418c | 39 | |
Jeco13 | 3:6e52b66c5a0c | 40 | //Part 1 |
Jeco13 | 3:6e52b66c5a0c | 41 | //Main takes in string text input from bluetooth module. Store in string variable |
Jeco13 | 3:6e52b66c5a0c | 42 | //call text_to_morse function on each character from input string variable |
Jeco13 | 3:6e52b66c5a0c | 43 | |
colson | 0:4e10b6c94be9 | 44 | int main() { |
colson | 4:62c590826ddb | 45 | |
Jeco13 | 9:3c1acc87b80c | 46 | //Function call for bluetooth text input |
Jeco13 | 9:3c1acc87b80c | 47 | dev.attach(&dev_recv, Serial::RxIrq); //calls text_to_morse function on bluetooth text inputs |
Jeco13 | 9:3c1acc87b80c | 48 | |
colson | 6:421ece74143e | 49 | //Variable word list for the game portion |
colson | 6:421ece74143e | 50 | //Feel free to add words, just update the array size |
colson | 6:421ece74143e | 51 | string wordlist[20] = {"Dog","Cat","Car","Tree","Star","Radio","Tea","Book","Hello","Bank","Bird","Bus","Red","Green","Blue","Coat","Dress","Shirt","Egg","Pear"}; |
colson | 6:421ece74143e | 52 | |
colson | 6:421ece74143e | 53 | |
colson | 5:5b86521e418c | 54 | //Creation of the binary search tree// |
colson | 6:421ece74143e | 55 | //I need to insert 2,8,9,0,+// |
colson | 8:78b057dd6da4 | 56 | node * newRoot = new node; |
colson | 8:78b057dd6da4 | 57 | insertdot('e', newRoot); |
colson | 8:78b057dd6da4 | 58 | node * eNode = newRoot->dot; |
colson | 8:78b057dd6da4 | 59 | insertdash('a', eNode); |
colson | 8:78b057dd6da4 | 60 | insertdot('i', eNode); |
colson | 8:78b057dd6da4 | 61 | cout << returnvalue(eNode->dash) <<endl; |
colson | 8:78b057dd6da4 | 62 | node * iNode = eNode->dot; |
colson | 8:78b057dd6da4 | 63 | insertdash('u',iNode); |
colson | 8:78b057dd6da4 | 64 | insertdot('s',iNode); |
colson | 8:78b057dd6da4 | 65 | node * sNode = iNode->dot; |
colson | 8:78b057dd6da4 | 66 | insertdash('v',sNode); |
colson | 8:78b057dd6da4 | 67 | insertdot('h',sNode); |
colson | 8:78b057dd6da4 | 68 | node * hNode = sNode->dot; |
colson | 8:78b057dd6da4 | 69 | insertdash('4',hNode); |
colson | 8:78b057dd6da4 | 70 | insertdot('5',hNode); |
colson | 8:78b057dd6da4 | 71 | node * vNode = sNode->dash; |
colson | 8:78b057dd6da4 | 72 | insertdash('3',vNode); |
colson | 8:78b057dd6da4 | 73 | node * uNode = iNode->dash; |
colson | 8:78b057dd6da4 | 74 | insertdot('f',uNode); |
colson | 8:78b057dd6da4 | 75 | node * aNode = eNode->dash; |
colson | 8:78b057dd6da4 | 76 | insertdot('r',aNode); |
colson | 8:78b057dd6da4 | 77 | insertdash('w',aNode); |
colson | 8:78b057dd6da4 | 78 | node * rNode = aNode->dot; |
colson | 8:78b057dd6da4 | 79 | insertdot('l',rNode); |
colson | 8:78b057dd6da4 | 80 | node * wNode = aNode->dash; |
colson | 8:78b057dd6da4 | 81 | insertdot('p',wNode); |
colson | 8:78b057dd6da4 | 82 | insertdash('j',wNode); |
colson | 8:78b057dd6da4 | 83 | node * jNode = wNode->dash; |
colson | 8:78b057dd6da4 | 84 | insertdash('1',jNode); |
colson | 8:78b057dd6da4 | 85 | insertdash('t',newRoot); |
colson | 8:78b057dd6da4 | 86 | node * tNode = newRoot->dash; |
colson | 8:78b057dd6da4 | 87 | insertdot('n',tNode); |
colson | 8:78b057dd6da4 | 88 | insertdash('m',tNode); |
colson | 8:78b057dd6da4 | 89 | node * nNode = tNode->dash; |
colson | 8:78b057dd6da4 | 90 | insertdot('d',nNode); |
colson | 8:78b057dd6da4 | 91 | insertdash('k',nNode); |
colson | 8:78b057dd6da4 | 92 | node * dNode = nNode->dot; |
colson | 8:78b057dd6da4 | 93 | insertdot('b',dNode); |
colson | 8:78b057dd6da4 | 94 | insertdash('x',dNode); |
colson | 8:78b057dd6da4 | 95 | node * bNode = dNode->dot; |
colson | 8:78b057dd6da4 | 96 | insertdot('6',bNode); |
colson | 8:78b057dd6da4 | 97 | insertdash('=',bNode); |
colson | 8:78b057dd6da4 | 98 | node * xNode = dNode->dash; |
colson | 8:78b057dd6da4 | 99 | insertdot('/',xNode); |
colson | 8:78b057dd6da4 | 100 | node * kNode = nNode->dash; |
colson | 8:78b057dd6da4 | 101 | insertdot('c',kNode); |
colson | 8:78b057dd6da4 | 102 | insertdash('y',kNode); |
colson | 8:78b057dd6da4 | 103 | node * mNode = tNode->dash; |
colson | 8:78b057dd6da4 | 104 | insertdot('g',mNode); |
colson | 8:78b057dd6da4 | 105 | insertdash('o',mNode); |
colson | 8:78b057dd6da4 | 106 | node * gNode = mNode->dot; |
colson | 8:78b057dd6da4 | 107 | insertdot('z',gNode); |
colson | 8:78b057dd6da4 | 108 | insertdash('q',gNode); |
colson | 8:78b057dd6da4 | 109 | node * zNode = gNode->dot; |
colson | 8:78b057dd6da4 | 110 | insertdot('7',zNode); |
colson | 8:78b057dd6da4 | 111 | |
colson | 8:78b057dd6da4 | 112 | //Syntax for traversing the tree |
colson | 8:78b057dd6da4 | 113 | /*node * newNode = new node; |
colson | 8:78b057dd6da4 | 114 | newNode = newRoot; |
colson | 8:78b057dd6da4 | 115 | |
colson | 8:78b057dd6da4 | 116 | *newNode = traverseDot(newNode); |
colson | 8:78b057dd6da4 | 117 | cout << returnvalue(newNode) << " return new node" << endl;*/ |
colson | 5:5b86521e418c | 118 | |
colson | 4:62c590826ddb | 119 | string newString = "YYZ"; |
colson | 4:62c590826ddb | 120 | |
colson | 4:62c590826ddb | 121 | for (int i = 0; i < newString.length(); i++){ |
Jeco13 | 9:3c1acc87b80c | 122 | //Text_to_morse(newString[i]); |
colson | 4:62c590826ddb | 123 | } |
colson | 4:62c590826ddb | 124 | |
colson | 4:62c590826ddb | 125 | char schar = 's'; |
colson | 4:62c590826ddb | 126 | char ochar = 'o'; |
colson | 0:4e10b6c94be9 | 127 | while(1) { |
colson | 4:62c590826ddb | 128 | uLCD.printf("do this\n"); |
Jeco13 | 9:3c1acc87b80c | 129 | //Text_to_morse(schar); |
Jeco13 | 9:3c1acc87b80c | 130 | // Text_to_morse(ochar); |
Jeco13 | 9:3c1acc87b80c | 131 | // Text_to_morse(schar); |
colson | 4:62c590826ddb | 132 | wait(0.5); |
colson | 0:4e10b6c94be9 | 133 | } |
colson | 0:4e10b6c94be9 | 134 | } |