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:
- colson
- Date:
- 2018-04-29
- Revision:
- 6:421ece74143e
- Parent:
- 5:5b86521e418c
- Child:
- 7:5a902d88277a
File content as of revision 6:421ece74143e:
#include "mbed.h"
#include "uLCD_4DGL.h"
AnalogOut speaker(p18);
DigitalOut led(p8);
DigitalOut myled(LED1);
DigitalOut testled(LED2);
DigitalOut otherled(LED3);
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.
testled = 1;
wait(0.5);
testled = 0;
wait(0.5);
}
void dash(){
//turn on speaker for 1s.
//turn on led for 1s.
//turn off speaker & led.
myled = 1;
wait(1.0);
myled = 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");
//testled = 1;
dash();
//wait(2);
dash();
//wait(w);
dash();
//wait(w);
//testled = 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.
}
class Tree {
public:
char value;
Tree *dot;
Tree *dash;
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 Tree::insertdot(char newValue, Tree *rootNode){
rootNode->dot = new Tree;
rootNode->dot->value = newValue;
rootNode->dot->dot = NULL;
rootNode->dot->dash = NULL;
return;
}
//Inserting an item on the "dash" side of a node
//See above for more comments/documentation
void Tree::insertdash(char newValue, Tree *rootNode){
rootNode->dash = new Tree;
rootNode->dash->value = newValue;
rootNode->dash->dot = NULL;
rootNode->dash->dash = NULL;
return;
}
//Return char type value stored in a given node
char returnvalue(Tree *rootNode){
return rootNode->value;
}
