Created
December 26, 2011 00:55
-
-
Save emberian/1520174 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Code: */ | |
#include <ctype.h> | |
#define speed 35 | |
#define word_time (speed * 3) | |
#define short_time (speed) | |
#define long_time (speed * 3) | |
#define space_time (speed * 7) | |
#define letter_pause (speed * 3) | |
#define long_pin 12 | |
#define short_pin 13 | |
#define DIT (blink(short_pin, short_time, letter_pause)) | |
#define DOT (blink(long_pin, long_time, letter_pause)) | |
#define WORDSEP (delay(space_time)) | |
#define MESSAGE "Hello, world" | |
void blink(int pin, int duration, int pause); | |
char *morse[133]; /* XXX */ | |
morse['A'] = "sl"; | |
morse['B'] = "lsss"; | |
morse['C'] = "lsls"; | |
morse['D'] = "lss"; | |
morse['E'] = "s"; | |
morse['F'] = "ssls"; | |
morse['G'] = "lls"; | |
morse['H'] = "ssss"; | |
morse['I'] = "ss"; | |
morse['J'] = "slll"; | |
morse['K'] = "lsl"; | |
morse['L'] = "slss"; | |
morse['M'] = "ll"; | |
morse['N'] = "ls"; | |
morse['O'] = "lll"; | |
morse['P'] = "slls"; | |
morse['Q'] = "llsl"; | |
morse['R'] = "sls"; | |
morse['S'] = "sss"; | |
morse['T'] = "l"; | |
morse['U'] = "ssl"; | |
morse['V'] = "sssl"; | |
morse['W'] = "sll"; | |
morse['X'] = "lssl"; | |
morse['Y'] = "lsll"; | |
morse['Z'] = "llss"; | |
morse['1'] = "sllll"; | |
morse['2'] = "sslll"; | |
morse['3'] = "sssll"; | |
morse['4'] = "ssssl"; | |
morse['5'] = "sssss"; | |
morse['6'] = "lssss"; | |
morse['7'] = "llsss"; | |
morse['8'] = "lllss"; | |
morse['9'] = "lllls"; | |
morse['0'] = "lllll"; | |
void setup() { | |
pinMode(short_pin, OUTPUT); | |
pinMode(long_pin, OUTPUT); | |
} | |
void blink(int pin, int duration, int pause) { | |
digitalWrite(pin, HIGH); | |
delay(duration); | |
digitalWrite(pin, LOW); | |
delay(pause); | |
} | |
void loop() { | |
char *c; | |
for (c = MESSAGE; *c != '\0'; c++) { /* Loop through message to send */ | |
if (*c == ' ') { | |
WORDSEP; | |
continue; | |
} | |
else if (isalnum(*c)) { /* Serializable as Morse */ | |
char *j; | |
for (j = morse[toupper(*c)]; *j != '\0'; j++) { | |
if (*j == 'l') { | |
DOT; | |
} | |
else { | |
DIT; | |
} | |
} | |
} | |
} | |
delay(2000); | |
} | |
/* output from Arduino IDE: | |
morse.cpp:23:1: error: ‘morse’ does not name a type | |
morse.cpp:24:1: error: ‘morse’ does not name a type | |
morse.cpp:25:1: error: ‘morse’ does not name a type | |
morse.cpp:26:1: error: ‘morse’ does not name a type | |
morse.cpp:27:1: error: ‘morse’ does not name a type | |
morse.cpp:28:1: error: ‘morse’ does not name a type | |
morse.cpp:29:1: error: ‘morse’ does not name a type | |
morse.cpp:30:1: error: ‘morse’ does not name a type | |
morse.cpp:31:1: error: ‘morse’ does not name a type | |
morse.cpp:32:1: error: ‘morse’ does not name a type | |
morse.cpp:33:1: error: ‘morse’ does not name a type | |
morse.cpp:34:1: error: ‘morse’ does not name a type | |
morse.cpp:35:1: error: ‘morse’ does not name a type | |
morse.cpp:36:1: error: ‘morse’ does not name a type | |
morse.cpp:37:1: error: ‘morse’ does not name a type | |
morse.cpp:38:1: error: ‘morse’ does not name a type | |
morse.cpp:39:1: error: ‘morse’ does not name a type | |
morse.cpp:40:1: error: ‘morse’ does not name a type | |
morse.cpp:41:1: error: ‘morse’ does not name a type | |
morse.cpp:42:1: error: ‘morse’ does not name a type | |
morse.cpp:43:1: error: ‘morse’ does not name a type | |
morse.cpp:44:1: error: ‘morse’ does not name a type | |
morse.cpp:45:1: error: ‘morse’ does not name a type | |
morse.cpp:46:1: error: ‘morse’ does not name a type | |
morse.cpp:47:1: error: ‘morse’ does not name a type | |
morse.cpp:48:1: error: ‘morse’ does not name a type | |
morse.cpp:49:1: error: ‘morse’ does not name a type | |
morse.cpp:50:1: error: ‘morse’ does not name a type | |
morse.cpp:51:1: error: ‘morse’ does not name a type | |
morse.cpp:52:1: error: ‘morse’ does not name a type | |
morse.cpp:53:1: error: ‘morse’ does not name a type | |
morse.cpp:54:1: error: ‘morse’ does not name a type | |
morse.cpp:55:1: error: ‘morse’ does not name a type | |
morse.cpp:56:1: error: ‘morse’ does not name a type | |
morse.cpp:57:1: error: ‘morse’ does not name a type | |
morse.cpp:58:1: error: ‘morse’ does not name a type | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment