Skip to content

Commit 485556d

Browse files
committed
Add Morse Arduino Library v1.0.0 with examples
1 parent 60fe9e0 commit 485556d

File tree

8 files changed

+209
-0
lines changed

8 files changed

+209
-0
lines changed

libraries/morse/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Morse Arduino Library
2+
3+
A simple Arduino library for decoding Morse code.
4+
It provides a lookup table and functions to translate Morse sequences (`.` and `-`) into letters and numbers.
5+
Reusable across projects for IoT, communication experiments, and custom input devices.
6+
7+
---
8+
9+
## Features
10+
- Decode Morse sequences (e.g. `".-" → A`).
11+
- Supports **A–Z** and **0–9**.
12+
- Lightweight: uses only a lookup table and string compare.
13+
- Works on all Arduino boards (`architectures=*`).
14+
15+
---
16+
17+
## Installation
18+
19+
### Method 1: Arduino IDE Library Manager
20+
_Not yet published to Library Manager – coming soon._
21+
22+
### Method 2: Manual Installation
23+
1. Download or clone this repo:
24+
```bash
25+
git clone https://github.com/aryankajiwala/Morse.git
26+
```
27+
2. Move the folder into your Arduino libraries folder:
28+
```
29+
Documents/Arduino/libraries/Morse/
30+
```
31+
3. Restart Arduino IDE.
32+
4. Include the library in your sketch:
33+
```cpp
34+
#include <Morse.h>
35+
```
36+
37+
---
38+
39+
## Usage
40+
41+
### Simple Test
42+
```cpp
43+
#include <Morse.h>
44+
45+
void setup() {
46+
Serial.begin(9600);
47+
48+
char test = decodeMorse(".-"); // should return 'A'
49+
Serial.print("Decoded: ");
50+
Serial.println(test);
51+
}
52+
53+
void loop() {
54+
}
55+
```
56+
57+
**Output:**
58+
```
59+
Decoded: A
60+
```
61+
62+
---
63+
64+
## API Reference
65+
### `char decodeMorse(const char* code)`
66+
- **Input:** Morse sequence as `const char*` (e.g., `".-"`).
67+
- **Output:** Corresponding ASCII character (`'A'`) or `'?'` if unknown.
68+
69+
---
70+
71+
## Roadmap
72+
- [ ] Add **encoder function** (`encodeMorse('A') → ".-"`).
73+
- [ ] Add support for **punctuation** (`. , ? !`).
74+
- [ ] Publish to Arduino Library Manager.
75+
76+
---
77+
78+
## Author
79+
**Aryan Kajiwala**
80+
81+
🔗 [GitHub](https://github.com/AryanKaji)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <Morse.h>
2+
3+
#define DOT_BUTTON 2
4+
#define DASH_BUTTON 3
5+
6+
String currentCode = "";
7+
unsigned long lastPressTime = 0;
8+
const unsigned long letterGap = 1500;
9+
10+
void setup() {
11+
pinMode(DOT_BUTTON, INPUT_PULLUP);
12+
pinMode(DASH_BUTTON, INPUT_PULLUP);
13+
Serial.begin(9600);
14+
}
15+
16+
void loop() {
17+
if (digitalRead(DOT_BUTTON) == LOW) {
18+
currentCode += ".";
19+
delay(300);
20+
lastPressTime = millis();
21+
}
22+
23+
if (digitalRead(DASH_BUTTON) == LOW) {
24+
currentCode += "-";
25+
delay(300);
26+
lastPressTime = millis();
27+
}
28+
29+
if (currentCode.length() > 0 && millis() - lastPressTime > letterGap) {
30+
char decoded = decodeMorse(currentCode.c_str());
31+
Serial.print(decoded);
32+
currentCode = "";
33+
}
34+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <Morse.h>
2+
3+
void setup() {
4+
Serial.begin(9600);
5+
Serial.println("Morse Library Example");
6+
Serial.println("----------------------");
7+
8+
// Decode a simple Morse sequence
9+
char letter = decodeMorse(".-"); // should return 'A'
10+
Serial.print("Decoded '.-': ");
11+
Serial.println(letter);
12+
13+
letter = decodeMorse("..."); // should return 'S'
14+
Serial.print("Decoded '...': ");
15+
Serial.println(letter);
16+
17+
letter = decodeMorse("----."); // should return '9'
18+
Serial.print("Decoded '----.': ");
19+
Serial.println(letter);
20+
21+
// Unknown sequence
22+
letter = decodeMorse("..--.."); // not defined
23+
Serial.print("Decoded '..--..': ");
24+
Serial.println(letter); // should print '?'
25+
}
26+
27+
void loop() {
28+
// Nothing here for now
29+
}

libraries/morse/keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
decodeMorse KEYWORD2
2+
MorseMap KEYWORD1

libraries/morse/library.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "Morse",
3+
"keywords": ["KEYWORD1", "KEYWORD2"],
4+
"repository": {
5+
"type": "git",
6+
"url": "https://github.com/AryanKaji/Morse.git"
7+
},
8+
"version": "1.0.0",
9+
"author": "Aryan Kajiwala",
10+
"maintainer": "Aryan Kajiwala <[email protected]>",
11+
"sentence": "A simple Arduino library for decoding Morse code.",
12+
"paragraph": "Provides a lookup table and functions to decode Morse sequences into characters. Can be reused across projects to interpret dot-dash sequences as letters and numbers. Includes functions for single letters and full string decoding.",
13+
"category": "Communication",
14+
"architectures": "*"
15+
}

libraries/morse/library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Morse
2+
version=1.0.0
3+
author=Aryan Kajiwala
4+
maintainer=Aryan Kajiwala <[email protected]>
5+
sentence=A simple Arduino library for decoding Morse code.
6+
paragraph=paragraph=Provides a lookup table and functions to decode Morse sequences into characters. Can be reused across projects to interpret dot-dash sequences as letters and numbers. Includes functions for single letters and full string decoding.
7+
category=Communication
8+
url=https://github.com/aryankajiwala/Morse
9+
architectures=*

libraries/morse/src/Morse.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "Morse.h"
2+
3+
// Morse lookup table (A–Z, 0–9)
4+
const MorseMap morseTable[] = {
5+
{".-", 'A'}, {"-...", 'B'}, {"-.-.", 'C'}, {"-..", 'D'}, {".", 'E'},
6+
{"..-.", 'F'}, {"--.", 'G'}, {"....", 'H'}, {"..", 'I'}, {".---", 'J'},
7+
{"-.-", 'K'}, {".-..", 'L'}, {"--", 'M'}, {"-.", 'N'}, {"---", 'O'},
8+
{".--.", 'P'}, {"--.-", 'Q'}, {".-.", 'R'}, {"...", 'S'}, {"-", 'T'},
9+
{"..-", 'U'}, {"...-", 'V'}, {".--", 'W'}, {"-..-", 'X'}, {"-.--", 'Y'},
10+
{"--..", 'Z'},
11+
12+
{"-----", '0'}, {".----", '1'}, {"..---", '2'}, {"...--", '3'}, {"....-", '4'},
13+
{".....", '5'}, {"-....", '6'}, {"--...", '7'}, {"---..", '8'}, {"----.", '9'}
14+
};
15+
16+
// Decode a Morse sequence into a character
17+
char decodeMorse(const char* code) {
18+
for (unsigned int i = 0; i < sizeof(morseTable) / sizeof(morseTable[0]); i++) {
19+
if (strcmp(code, morseTable[i].code) == 0) {
20+
return morseTable[i].letter;
21+
}
22+
}
23+
return '?'; // Unknown sequence
24+
}

libraries/morse/src/Morse.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef MORSE_H
2+
#define MORSE_H
3+
4+
#include <Arduino.h>
5+
6+
// Morse lookup table entry
7+
struct MorseMap {
8+
const char* code;
9+
char letter;
10+
};
11+
12+
// Function to decode a Morse sequence into a character
13+
char decodeMorse(const char* code);
14+
15+
#endif

0 commit comments

Comments
 (0)