Morse Encoder With Codaic
This example demonstrates how to convert text into Morse code using the haptic feedback module (vibrator) on iOS devices. When completed, your project should look similar to these pictures.
Supplies
- iPhone with iOS 26+
- Codaic v1.4+
Introduction
The foundation of this example is the Morse code alphabet. For detailed information, see Wikipedia.
Here's a Lua representation that maps letters and numbers to their Morse code symbols:
Next, consider the timing rules for Morse code:
- A dot/dit equals one unit (called the dit length)
- A dash/dah equals three units
- A space between letter parts equals one unit
- A space between letters equals three units
- A space between words equals seven units
We'll set the dot/dit length to 100 ms, which is the minimum interval at which Codaic can toggle the vibrator. This makes a dash/dah 300 ms long.
Implementation
After collecting all the basic information, it's time to start the project. First, add a new project and give it a name. Then open it and place the nodes as shown above. You will need a Custom node (Morse-Encoder), the Log node, and the Vibrator node. For the Log and Vibrator nodes, you can simply use the provided implementations without modification.
Morse-Encoder Node
This custom node converts a word into Morse code and generates the output signal to control the haptic feedback module (vibrator).
The code is organized into three main sections:
- Setup: Initializes the Morse code dictionary that maps each letter and digit to its corresponding symbol (dots and dashes).
- Helper Functions:
- wordToMorse() - Transforms an entire word into Morse code by converting each character to uppercase (for dictionary lookup) and joining them with proper spacing
- Main Loop: Continuously reads the word "Codaic", converts it to Morse code, and then iterates through each symbol to:
- Determine if it's a dot, dash, or space
- Control the vibrator duration accordingly (100ms for dot, 300ms for dash) and send it to the log
- Add appropriate gaps between symbols and words
Outlook
That's it! Now press the play button in the top right corner and listen to your phone. Congratulations on completing your first Codaic project!
For an extra challenge, try replacing the Vibrator node with the Torch node to create a visual representation of your Morse code using light pulses. In the meantime, I will continue improving Codaic and provide more examples.
Transparency Note: I am the developer of Codaic. While I hope you find this example and the app useful, please be aware of this potential conflict of interest. I welcome your feedback, suggestions, or questions—your input helps me improve Codaic for everyone.
Best, Oliver