Last active
December 31, 2015 03:48
-
-
Save codepope/7929534 to your computer and use it in GitHub Desktop.
This file contains 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
// Morse Code - USE MQTT! | |
// based on a project from 30 Arduino Projects for the Evil Genius | |
// thanks to Simon Monk | |
// Andy Piper @andypiper, Nov 2013 | |
// Dj @codepope, Dec 2013 (Putting it all in a for loop - Just change the message | |
char* message="use mqtt"; | |
int ledPin = 12; | |
char* letters[] = { | |
".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", // A-I | |
".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", // J-R | |
"...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.." // S-Z | |
}; | |
char* numbers[] = {"-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----."}; | |
int dotDelay = 200; | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); | |
for(int n=0;n<3;n++) { | |
digitalWrite(ledPin, HIGH); // quick blinks to acknowledge setup | |
delay(100); | |
digitalWrite(ledPin, LOW); | |
delay(100); | |
} | |
delay(dotDelay * 0); // before we get started | |
} | |
void loop() | |
{ | |
for(int n=0;n<strlen(message);n++) { | |
char ch=message[n]; | |
if(ch==32) { | |
delay(dotDelay * 14); | |
} else { | |
flashSequence(letters[ch - 'a']); | |
} | |
} | |
delay(dotDelay * 14); // end message | |
} | |
void flashSequence(char* sequence) | |
{ | |
int i = 0; | |
while (sequence[i] != NULL) | |
{ | |
flashDotOrDash(sequence[i]); | |
i++; | |
} | |
delay(dotDelay * 3); // gap between letters | |
} | |
void flashDotOrDash(char dotOrDash) | |
{ | |
digitalWrite(ledPin, HIGH); | |
if (dotOrDash == '.') | |
{ | |
delay(dotDelay); | |
} | |
else // must be a - | |
{ | |
delay(dotDelay * 3); | |
} | |
digitalWrite(ledPin, LOW); | |
delay(dotDelay); // gap between flashes | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better :-) also makes it more ready to receive MQTT messages and swap in for the value of char* message :)