Skip to content

Instantly share code, notes, and snippets.

@darashi
Created February 10, 2012 16:42
Show Gist options
  • Save darashi/1790725 to your computer and use it in GitHub Desktop.
Save darashi/1790725 to your computer and use it in GitHub Desktop.
HELLO WORLD from Arduino
#define LED 13
#define T 100 // speed
char *morse_pattern[] = {
"._", "_...", "_._.", "_..", ".", ".._.", "__.",
"....", "..", ".___", "_._", "._..", "__",
"_.", "___", ".__.", "__._", "._.", "...", "_",
".._", "..._", ".__", "_.._", "__._", "__.."
};
void setup() {
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
delay(T*7);
}
void morse(int output, int time, char *str) {
int i, j;
for (i=0; i<strlen(str); i++) {
char *c = str+i;
if ('A' <= *c && *c <= 'Z') {
char *pattern = morse_pattern[*c - 'A'];
for (j=0; j<strlen(pattern); j++) {
digitalWrite(output, HIGH);
if(pattern[j] == '.') {
delay(time * 1);
}
else {
delay(time * 3);
}
digitalWrite(output, LOW);
delay(time * 1);
}
delay(time * 2);
} else {
delay(time * 3);
}
}
delay(time * 4);
}
void loop() {
char *str = "HELLO WORLD";
morse(LED, T, str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment