An Arduino-based communication system that instantly converts text strings into Morse code light signals. Leveraging optimized JSON mapping for flexible character encoding and precise timing control.
Complete C++ logic for character mapping and signal generation
#include <ArduinoJson.h>
#define USI unsigned short int
#define USIC USI const
USIC PIN = 13;
USIC SHORT = 700;
USIC LONG = 2000;
USIC BREAK = 100;
const char inputText[] = "bashar";
StaticJsonDocument<1047> doc;
USI runing = 1;
void setup() {
pinMode(PIN, OUTPUT);
Serial.begin(9600);
while (!Serial) continue;
// JSON Mapping for Morse Code Characters
const char json[] = "{\"0\":\"----\",\"1\":\".----\",\"2\":\"..---\",...}";
DeserializationError error = deserializeJson(doc, json);
if (error) {
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.f_str());
return;
}
}
void loop() {
if (runing) {
Serial.println("Start:");
USIC inputLen = strlen(inputText);
for (USI inputIndex = 0; inputIndex < inputLen; inputIndex++) {
const char currentChar = inputText[inputIndex];
const char* morse_code = doc[¤tChar];
// Signal Generation Logic
USIC morseLen = strlen(morse_code);
for (USI morseIndex = 0; morseIndex < morseLen; morseIndex++) {
int morse_part = morse_code[morseIndex];
digitalWrite(PIN, HIGH);
if (morse_part == 45) { // Dash case '-'
delay(LONG);
} else { // Dot case '.'
delay(SHORT);
}
digitalWrite(PIN, LOW);
delay(BREAK);
}
}
digitalWrite(PIN, LOW);
runing = 0;
}
}
Smart embedded solution design
Uses ArduinoJson library to efficiently deserialize and map characters to their Morse code equivalents.
Accurate control of short (dot), long (dash), and break intervals for standard Morse code complaince.
Direct Hardware abstraction to control onboard LED (Pin 13) for visible signal transmission.
Real-time serial console feedback for monitoring current character processing and signal status.
Hardware and software components