Skip to content

Commit

Permalink
Added morse coder example
Browse files Browse the repository at this point in the history
  • Loading branch information
josejuansanchez committed Sep 4, 2016
1 parent 2c64b1a commit 5cea43f
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
58 changes: 58 additions & 0 deletions experimental/morse_code/MorseCodeAlphabet.h
@@ -0,0 +1,58 @@
// Reference: https://gist.github.com/madc/4474559

static const struct {
const char letter;
const char *code;
} MorseCodeAlphabet[] =
{
{ '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', "--.." },
{ ' ', " " },

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

{ '.', "·–·–·–" },
{ ',', "--..--" },
{ '?', "..--.." },
{ '!', "-.-.--" },
{ ':', "---..." },
{ ';', "-.-.-." },
{ '(', "-.--." },
{ ')', "-.--.-" },
{ '"', ".-..-." },
{ '@', ".--.-." },
{ '&', ".-..." },
};
44 changes: 44 additions & 0 deletions experimental/morse_code/morse_code.ino
@@ -0,0 +1,44 @@
#include <NanoPlayBoard.h>
#include "MorseCodeAlphabet.h"

#define WPM 20
#define DOT_LENGTH 1200 / WPM
#define PITCH 550

NanoPlayBoard board;

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

void loop() {
String message = " ... --- ... ";

for(int i = 0; i < message.length(); i++) {
switch(message[i]) {
case '.':
board.rgb.on();
board.buzzer.playTone(PITCH);
delay(DOT_LENGTH);
board.rgb.off();
board.buzzer.stopTone();
delay(DOT_LENGTH);
break;

case '-':
board.rgb.on();
board.buzzer.playTone(PITCH);
delay(DOT_LENGTH * 3);
board.rgb.off();
board.buzzer.stopTone();
delay(DOT_LENGTH);
break;

case ' ':
board.rgb.off();
board.buzzer.stopTone();
delay(DOT_LENGTH);
break;
}
}
}

0 comments on commit 5cea43f

Please sign in to comment.