Created
September 5, 2014 16:13
-
-
Save ed-george/da87fc4daedfd288c885 to your computer and use it in GitHub Desktop.
Arduino Morse with dual color LED
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
#define GREEN_LED 8 | |
#define RED_LED 12 | |
#define DOT '.' | |
#define DASH '-' | |
#define PIN_DELAY 500 | |
char *ascii = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,?'!/()&:;=+-_\"$@"; | |
char *code[] = { | |
".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","-----",".----","..---","...--","....-",".....","-....","--...","---..","----.",".-.-.-","--..--","..--..",".----.","-.-.--","-..-.","-.--.","-.--.-",".-...","---...","-.-.-.","-...-",".-.-.","-....-","..--.-",".-..-.","...-..-",".--.-." | |
}; | |
// the setup routine runs once when you press reset: | |
void setup() { | |
pinMode(GREEN_LED, OUTPUT); | |
pinMode(RED_LED, OUTPUT); | |
} | |
void parseMorse(char *code_char){ | |
int i; | |
int length = strlen (code_char); | |
for (i = 0; i < length; i++){ | |
int pin; | |
if(code_char[i] == DOT){ | |
pin = GREEN_LED; | |
}else{ | |
pin = RED_LED; | |
} | |
digitalWrite(pin, HIGH); | |
delay(PIN_DELAY); | |
digitalWrite(pin, LOW); | |
delay(PIN_DELAY); | |
} | |
} | |
void loop() { | |
char *message = "BOPPL"; | |
int length = strlen (message); | |
int i; | |
for( i = 0; i < length; i++ ){ | |
char ch = toupper(message[i]); | |
parseMorse(code[ch - 'A']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment