Skip to content

Instantly share code, notes, and snippets.

@ed-george
Created September 5, 2014 16:13
Show Gist options
  • Save ed-george/da87fc4daedfd288c885 to your computer and use it in GitHub Desktop.
Save ed-george/da87fc4daedfd288c885 to your computer and use it in GitHub Desktop.
Arduino Morse with dual color LED
#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