Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions libraries/morse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Morse Arduino Library

A simple Arduino library for decoding Morse code.

Check failure on line 3 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0; Actual: 2]

Check failure on line 3 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0; Actual: 2]
It provides a lookup table and functions to translate Morse sequences (`.` and `-`) into letters and numbers.

Check failure on line 4 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0; Actual: 2]

Check failure on line 4 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0; Actual: 2]
Reusable across projects for IoT, communication experiments, and custom input devices.

---

## Features

- Decode Morse sequences (e.g. `".-" → A`).
- Supports **A–Z** and **0–9**.
- Lightweight: uses only a lookup table and string compare.
- Works on all Arduino boards (`architectures=*`).

---

## Installation

### Method 1: Arduino IDE Library Manager

_Not yet published to Library Manager – coming soon._

### Method 2: Manual Installation

1. Download or clone this repo:
```bash
git clone https://github.com/aryankajiwala/Morse.git
```
2. Move the folder into your Arduino libraries folder:

Check failure on line 30 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Ordered list item prefix [Expected: 1; Actual: 2; Style: 1/1/1]

Check failure on line 30 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Ordered list item prefix [Expected: 1; Actual: 2; Style: 1/1/1]
```
Documents/Arduino/libraries/Morse/
```
3. Restart Arduino IDE.

Check failure on line 34 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Ordered list item prefix [Expected: 1; Actual: 3; Style: 1/1/1]

Check failure on line 34 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Ordered list item prefix [Expected: 1; Actual: 3; Style: 1/1/1]
4. Include the library in your sketch:

Check failure on line 35 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Ordered list item prefix [Expected: 1; Actual: 4; Style: 1/1/1]

Check failure on line 35 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Ordered list item prefix [Expected: 1; Actual: 4; Style: 1/1/1]
```cpp
#include <Morse.h>
```

---

## Usage

### Simple Test

```cpp
#include <Morse.h>

void setup() {
Serial.begin(9600);

char test = decodeMorse(".-"); // should return 'A'
Serial.print("Decoded: ");
Serial.println(test);
}

void loop() {
}
```

**Output:**

```
Decoded: A
```

---

## API Reference

### `char decodeMorse(const char* code)`

- **Input:** Morse sequence as `const char*` (e.g., `".-"`).
- **Output:** Corresponding ASCII character (`'A'`) or `'?'` if unknown.

---

## Roadmap

- [ ] Add **encoder function** (`encodeMorse('A') → ".-"`).
- [ ] Add support for **punctuation** (`. , ? !`).
- [ ] Publish to Arduino Library Manager.

---

## Author

**Aryan Kajiwala**

Check failure on line 88 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0; Actual: 2]

Check failure on line 88 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0; Actual: 2]
📧 [email protected]

Check failure on line 89 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0; Actual: 2]

Check failure on line 89 in libraries/morse/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces [Expected: 0; Actual: 2]
🔗 [GitHub](https://github.com/AryanKaji)
34 changes: 34 additions & 0 deletions libraries/morse/examples/ButtonMorse/ButtonMorse.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <Morse.h>

#define DOT_BUTTON 2
#define DASH_BUTTON 3

String currentCode = "";
unsigned long lastPressTime = 0;
const unsigned long letterGap = 1500;

void setup() {
pinMode(DOT_BUTTON, INPUT_PULLUP);
pinMode(DASH_BUTTON, INPUT_PULLUP);
Serial.begin(9600);
}

void loop() {
if (digitalRead(DOT_BUTTON) == LOW) {
currentCode += ".";
delay(300);
lastPressTime = millis();
}

if (digitalRead(DASH_BUTTON) == LOW) {
currentCode += "-";
delay(300);
lastPressTime = millis();
}

if (currentCode.length() > 0 && millis() - lastPressTime > letterGap) {
char decoded = decodeMorse(currentCode.c_str());
Serial.print(decoded);
currentCode = "";
}
}
29 changes: 29 additions & 0 deletions libraries/morse/examples/HelloMorse/HelloMorse.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <Morse.h>

void setup() {
Serial.begin(9600);
Serial.println("Morse Library Example");
Serial.println("----------------------");

// Decode a simple Morse sequence
char letter = decodeMorse(".-"); // should return 'A'
Serial.print("Decoded '.-': ");
Serial.println(letter);

letter = decodeMorse("..."); // should return 'S'
Serial.print("Decoded '...': ");
Serial.println(letter);

letter = decodeMorse("----."); // should return '9'
Serial.print("Decoded '----.': ");
Serial.println(letter);

// Unknown sequence
letter = decodeMorse("..--.."); // not defined
Serial.print("Decoded '..--..': ");
Serial.println(letter); // should print '?'
}

void loop() {
// Nothing here for now
}
2 changes: 2 additions & 0 deletions libraries/morse/keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
decodeMorse KEYWORD2
MorseMap KEYWORD1
15 changes: 15 additions & 0 deletions libraries/morse/library.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Morse",
"keywords": ["KEYWORD1", "KEYWORD2"],
"repository": {
"type": "git",
"url": "https://github.com/AryanKaji/Morse.git"
},
"version": "1.0.0",
"author": "Aryan Kajiwala",
"maintainer": "Aryan Kajiwala <[email protected]>",
"sentence": "A simple Arduino library for decoding Morse code.",
"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.",
"category": "Communication",
"architectures": "*"
}
9 changes: 9 additions & 0 deletions libraries/morse/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=Morse
version=1.0.0
author=Aryan Kajiwala
maintainer=Aryan Kajiwala <[email protected]>
sentence=A simple Arduino library for decoding Morse code.
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.
category=Communication
url=https://github.com/aryankajiwala/Morse
architectures=*
24 changes: 24 additions & 0 deletions libraries/morse/src/Morse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "Morse.h"

// Morse lookup table (A–Z, 0–9)
const MorseMap morseTable[] = {
{".-", 'A'}, {"-...", 'B'}, {"-.-.", 'C'}, {"-..", 'D'}, {".", 'E'},
{"..-.", 'F'}, {"--.", 'G'}, {"....", 'H'}, {"..", 'I'}, {".---", 'J'},
{"-.-", 'K'}, {".-..", 'L'}, {"--", 'M'}, {"-.", 'N'}, {"---", 'O'},
{".--.", 'P'}, {"--.-", 'Q'}, {".-.", 'R'}, {"...", 'S'}, {"-", 'T'},
{"..-", 'U'}, {"...-", 'V'}, {".--", 'W'}, {"-..-", 'X'}, {"-.--", 'Y'},
{"--..", 'Z'},

{"-----", '0'}, {".----", '1'}, {"..---", '2'}, {"...--", '3'}, {"....-", '4'},
{".....", '5'}, {"-....", '6'}, {"--...", '7'}, {"---..", '8'}, {"----.", '9'}
};

// Decode a Morse sequence into a character
char decodeMorse(const char* code) {
for (unsigned int i = 0; i < sizeof(morseTable) / sizeof(morseTable[0]); i++) {
if (strcmp(code, morseTable[i].code) == 0) {
return morseTable[i].letter;
}
}
return '?'; // Unknown sequence
}
15 changes: 15 additions & 0 deletions libraries/morse/src/Morse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef MORSE_H
#define MORSE_H

#include <Arduino.h>

// Morse lookup table entry
struct MorseMap {
const char* code;
char letter;
};

// Function to decode a Morse sequence into a character
char decodeMorse(const char* code);

#endif
Loading