Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed 4DGL-uLCD-SE
Fork of morseCode_1 by
Header_file.h
- Committer:
- Jeco13
- Date:
- 2018-05-01
- Revision:
- 9:3c1acc87b80c
- Parent:
- 8:78b057dd6da4
File content as of revision 9:3c1acc87b80c:
#include "mbed.h" #include "uLCD_4DGL.h" AnalogOut speaker(p18); DigitalOut led(p8); 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 void dot(){ //turn on speaker for 0.5s. //turn on led for 0.5s. //turn off speaker & led. led2 = 1; wait(0.5); led2 = 0; wait(0.5); } void dash(){ //turn on speaker for 1s. //turn on led for 1s. //turn off speaker & led. led3 = 1; wait(1.0); led3 = 0; wait(0.5); } //I commented out the debug outputs since I solved the problem of what was wrong but it could be nice to keep around, I guess void Text_to_morse(char input_char){ //function takes in characters at a time. call dot & dash appropriately for detected char //int w = 0.5; //wait duration in-between led blinks and speaker clicks //uLCD.printf("input: %c\n",input_char); //Debug output, feel free to comment out if(input_char == 'a' || input_char == 'A'){ //uLCD.printf("a\n"); dot(); //wait(w); //wait 0.5s in between dash(); //wait(w); } else if(input_char == 'b' || input_char == 'B'){ //uLCD.printf("b\n"); dash(); //wait(w); dot(); //wait(w); dot(); //wait(w); dot(); //wait(w); } else if(input_char == 'c'||input_char == 'C'){ //uLCD.printf("c\n"); dash(); //wait(w); dot(); //wait(w); dash(); //wait(w); dot(); //wait(w); } else if(input_char == 'd'||input_char == 'D'){ //uLCD.printf("d\n"); dash(); //wait(w); dot(); //wait(w); dot(); //wait(w); }else if(input_char == 'e'||input_char == 'E'){ //uLCD.printf("e\n"); dot(); //wait(w); } else if(input_char == 'f'||input_char == 'F'){ //uLCD.printf("f\n"); dot(); //wait(w); dot(); //wait(w); dash(); //wait(w); dot(); //wait(w); } else if(input_char == 'g'||input_char == 'G'){ //uLCD.printf("g\n"); dash(); //wait(w); dash(); //wait(w); dot(); //wait(w); } else if(input_char == 'h'||input_char == 'H'){ //uLCD.printf("h\n"); dot(); //wait(w); dot(); //wait(w); dot(); //wait(w); dot(); //wait(w); } else if(input_char == 'i'||input_char == 'I'){ //uLCD.printf("i\n"); dot(); //wait(w); dot(); //wait(w); } else if(input_char == 'j'||input_char == 'J'){ //uLCD.printf("j\n"); dot(); //wait(w); dash(); //wait(w); dash(); //wait(w); dash(); //wait(w); } else if(input_char == 'k'||input_char == 'K'){ //uLCD.printf("k\n"); dash(); //wait(w); dot(); //wait(w); dash(); //wait(w); } else if(input_char == 'l'||input_char == 'L'){ //uLCD.printf("l\n"); dot(); //wait(w); dash(); //wait(w); dot(); //wait(w); dot(); //wait(w); } else if(input_char == 'm'||input_char == 'M'){ //uLCD.printf("m\n"); dash(); //wait(w); dash(); //wait(w); } else if(input_char == 'n'||input_char == 'N'){ //uLCD.printf("n\n"); dash(); //wait(w); dot(); //wait(w); } else if(input_char == 'o'|| input_char == 'O'){ //uLCD.printf("o\n"); //led2 = 1; dash(); //wait(2); dash(); //wait(w); dash(); //wait(w); //led2 = 0; } else if(input_char == 'p'||input_char == 'P'){ //uLCD.printf("p\n"); dot(); //wait(w); dash(); //wait(w); dash(); //wait(w); dot(); //wait(w); } else if(input_char == 'q'||input_char == 'Q'){ //uLCD.printf("q\n"); dash(); dash(); dot(); dash(); } else if(input_char == 'r'||input_char == 'R'){ //uLCD.printf("r\n"); dot(); dash(); dot(); } else if(input_char == 's'||input_char == 'S'){ //uLCD.printf("s\n"); //otherled = 1; dot(); dot(); dot(); //otherled = 0; } else if(input_char == 't'||input_char == 'T'){ //uLCD.printf("t\n"); dash(); } else if(input_char == 'u'||input_char == 'U'){ //uLCD.printf("u\n"); dot(); dot(); dash(); } else if(input_char == 'v'||input_char == 'V'){ //uLCD.printf("v\n"); dot(); dot(); dot(); dash(); } else if(input_char == 'w'||input_char == 'W'){ //uLCD.printf("w\n"); dot(); dash(); dash(); } else if(input_char == 'x'||input_char == 'X'){ //uLCD.printf("x\n"); dash(); dot(); dot(); dash(); } else if(input_char == 'y'||input_char == 'Y'){ //uLCD.printf("y\n"); dash(); dot(); dash(); dash(); } else if(input_char == 'z'||input_char == 'Z'){ //uLCD.printf("z\n"); dash(); dash(); dot(); dot(); } else if(input_char == '0'){ dash(); dash(); dash(); dash(); dash(); } else if(input_char == '1'){ dot(); dash(); dash(); dash(); dash(); } else if(input_char == '2'){ dot(); dot(); dash(); dash(); dash(); } else if(input_char == '3'){ dot(); dot(); dot(); dash(); dash(); } else if(input_char == '4'){ dot(); dot(); dot(); dot(); dash(); } else if(input_char == '5'){ dot(); dot(); dot(); dot(); dot(); } else if(input_char == '6'){ dash(); dot(); dot(); dot(); dot(); } else if(input_char == '7'){ dash(); dash(); dot(); dot(); dot(); } else if(input_char == '8'){ dash(); dash(); dash(); dot(); dot(); } else if(input_char == '9'){ dash(); dash(); dash(); dash(); dot(); } else{wait(1);}//error character, or space character. } struct node { char value; node * dot; node * dash; node(){ value = '*'; dot = NULL; dash = NULL; } }; class Tree { public: node *root; Tree(){} Tree createRoot(); //void insertdot(char newValue, Tree *rootNode); //void insertdash(char newValue, Tree *rootNode); //char returnvalue(Tree *rootNode); //void deleteNode(Tree *deleteNode); //Didn't see the need for a delete function since the tree is pretty static }; //Inserting an item on the "dot" side of a node //Adds the value, and pointers go to NULL //The current intent is that by pointing to a NULL type, we can know when to top traversing. //I see our telegraph key having a separate function that will return a Tree node when traversing //But if a NULL is pointed to next, then it'll return the node that it's already looking at //If any of these comments make sense void insertdot(char newValue, node * rootNode){ node *temp = new node; rootNode->dot = temp; temp->value = newValue; temp->dot = NULL; temp->dash = NULL; return; } //Inserting an item on the "dash" side of a node //See above for more comments/documentation void insertdash(char newValue, node * rootNode){ node *temp = new node; rootNode->dash = temp; temp->value = newValue; temp->dot = NULL; temp->dash = NULL; return; } //Return char type value stored in a given node char returnvalue(node *rootNode){ return rootNode->value; } node traverseDot(node * rootNode){ node * tempNode = new node; if(rootNode->dot == NULL){ printf("null\n"); return * rootNode; } else{ //cout << returnvalue(rootNode) << "return root \n" << returnvalue(rootNode->dot) << " return dot" << endl; rootNode = rootNode->dot; return *rootNode; } } node traverseDash(node * rootNode){ if(rootNode->dash == NULL){ printf("null\n"); return * rootNode; } else{ //cout << returnvalue(rootNode) << "return root \n" << returnvalue(rootNode->dash) << " return dash" << endl; rootNode = rootNode->dash; return * rootNode; } }