Hi all,
I decided to treat myself to an Arduino UNO and wrote my first little program, this morning. Nothing amazing and certainly not optimized but figured other n00bs might like it to play with or use it as an example.
In short, it is a Morse encoder. Currently, it only encodes the alphabet: A-Z. It would not take much effort to add in a whole bunch of other characters.
I personally used an LED for the output since my wife was getting annoyed by the buzzer I originally connected
Anyways, here is the code. I hope someone finds it useful.
//pin to use as output
int morseLED = 2;
//for converting characters to array index
int offsetInt = 65;
//delays
int dotDelay = 1;
int dashDelay = 3;
int characterDelay = 3;
int ddDelay = 1;
int timeMultiplier = 100;
//array containing morse patterns
String morseAlphabet[] = {
  ".-",   //A
  "-...",  //B
  "-.-.",  //C
  "-..",  //D
  ".",   //E
  "..-.",  //F
  "--.",  //G
  "....",  //H
  "..",   //I
  ".---",  //J
  "-.-",  //K
  ".-..",  //L
  "--",   //M
  "-.",   //N
  "---",  //O
  ".--.",  //P
  "--.-",  //Q
  ".-.",  //R
  "...",  //S
  "-",   //T
  "..-",  //U
  "...-",  //V
  ".--",  //W
  "-..-",  //X
  "-.--",  //Y
  "--.."  //Z
};
Â
void setup(){
 pinMode(morseLED,OUTPUT); //set the pin for the led as an output
}
//main morse string encoding function
void EncodeMorseString(String morseString){
Â
 //for each character of the input string
 for (int i = 0; i < morseString.length(); i++){
 Â
  //uppercase it for consistency/array lookup
  char upperChar = toupper(morseString[i]);
 Â
  //while there are characters to process...
  for (int j = 0; j < morseAlphabet[upperChar-offsetInt].length(); j++){
  Â
   //find out if it's a dot or a dash
   if(morseAlphabet[upperChar-offsetInt][j] == '.')
   {
    //output a dot
    digitalWrite(morseLED, HIGH);
    delay(dotDelay*timeMultiplier);
    digitalWrite(morseLED, LOW);
    delay(ddDelay*timeMultiplier);
   }
   else if (morseAlphabet[upperChar-offsetInt][j] == '-'){
    //output a dash
    digitalWrite(morseLED, HIGH);
    delay(dashDelay*timeMultiplier);
    digitalWrite(morseLED, LOW);
    delay(ddDelay*timeMultiplier);
   }
  }
  //wait a short while before outputting next character
  delay(characterDelay*timeMultiplier);
 }
}
void loop(){
 EncodeMorseString("SOS"); //output message
 while(true); //loop indefinitely
}