This is a library that handles Morse code inputs and outputs on Phi-1 and Phi-2 shields, as pictured above. You can modify it to work on any display with a couple of buttons and a speaker. With this library, you can ask user to key in Morse code, get the character corresponding to the Morse code. You can also pass a string to the library and get it translated into di and dah output on a speaker. The example code is an interactive Morse code translator, which also shows off the elaborate Phi_prompt interactive user interface you may be interested in using.
I have always wanted to learn Morse code. Who knows when a fateful event happens and I could be stranded on an island with Morse code my only means of communication?! Anyway, I have made several attempt at a Morse code translator/trainer in the past. This is the most recent post with the trainer. Now it time to turn my codes into a library so others can readily use Morse code input/output in their own program without having to go through what I went through.
What it does:
Takes user keyed in Morse inputs and translates into characters.
Takes a text string and translates into Morse output on a speaker.
Determine the character corresponding to a string with di and dah. Eg. if you provide “.-..” the function will return ‘L’.
Pictures and Videos:
Here is a video of the example program in action on a Phi-2 shield:
A reference manual is included in the library download.
First you need to initialize the library. Please follow the sample code to initialize the library. These code snippets work after the initialization.
void morse_period(int p);
This sets the period of a di.
void morse_out(char* message);
This outputs the message to the speaker at the previously decided period.
char morse_in(byte col, byte row);
This returns the character keyed in by the operator. The Morse code di and dah will be displayed at LCD location (col,row). So if you key in ‘L’, the Morse code “.-..” will display at location (col,row).
It calls morse_find() to determine the character.
Returns -1 if input is invalid – . combination.
Returns -2 if detected too long. This may be used as erase previous character.
//This returns one character keyed in.
char morse_find(char *detected);
This returns a character if the provided character array detected is a valid Morse code sequence.
Returns -1 if the sequence is invalid.
Serial.print(ret); // This prints an L.
The following are static functions only called by the above library functions. You don’t need to call them anyway.
This makes a short beep corresponding to di.
This makes a short beep corresponding to dah.
This monitors the keypad and returns the following results:
Returns 0 if detected a pause. You can discard this value.
Returns -1 if detected up button.
Returns -2 if detected down button.
Returns -3 if detected left button. This may be used to erase previous character.
Returns -4 if detected right button. This may be used as adding space.
Returns -6 if detected escape button. This may be used to escape.
Returns -127 if detected invalid signal or too short.
Returns -128 if detected too long.
Returns ‘-‘ or ‘.’ otherwise
The function doesn’t check if enough pause is used after the – or .
Library and phi_morse translator project code:
Everything is on my libraries and code download page:
This version is compatible with Arduino 1.6.0
Reference manual is included.
The library download includes an example project, the Morse code translator for Phi-2 shield. If you have a Phi-1 shield, please follow the instruction in the code to make one modification. It provides the following functions:
- Interactive menu (constructed with phi_prompt library)
- Encode: enter text and listen to Morse code di and dah (use up and down to cycle through characters and left right to move within a word)
- Decode: key in di and dah and get translated into characters (use B button to key in Morse code, left and right to move cursor, escape to end)
- Library: listen to Morse code of a bunch of preselected words, revise the code and add your words (function made possible by phi_prompt library)
- Change Morse code translator speed
- Show credit
If you like this project, please consider purchasing a Phi-2 shield.
First download the package, then extract the files under your Arduino Sketchbook/Libraries folder, so that the three files will be under c:/Arduino22/Sketchbooks/Libraries/phi_morse/ (Just example, your directory may be different)
Then install all dependent libraries listed in the dependencies section below.
Close all Arduino IDE windows.
Reopen Arduino IDE, open a sketchbook you want to use the phi_buttons. Then choose under the Arduino IDE menu Sketch->Import library->phi_morse
The Arduino IDE automatically creates a line in the beginning of your sketchbook: #include <phi_morse.h>
OK you’re done!