Arduino project – Mores code generator

Using an arduino, I created a Mores code generator. In the video, the arduino is connected to a tiny buzzer, which makes the sound. Code is posted below. In the video, the arduino welcomes you to wikipedia. I used the example on wiki so that I could compare their waveforms to confirm that arduino has actually generated the correct Mores code.

Here is a picture of waveform of my generated message compared with wikipedia’s original message to show my generator works:

Source code:

#define period 90 //13.33 WPM
#define buzzerPin 11
// Dr. Liu 10/03/2010
unsigned char message[]="WELCOME TO WIKIPEDIA, THE FREE ENCYCLOPEDIA THAT ANYONE CAN EDIT.   ";
unsigned char space_to_Z[][8]={" ", "!-.-.--", "\".-..-.", "# ", "$ ", "% ", "&.-...", "\'.----.",
 "(-.--.", ")-.--.-", "* ", "+.-.-.", ",--..--", "m-....-", "p.-.-.-", "/-..-.", "0-----", "1.----",
 "2..---", "3...--", "4....-", "5.....", "6-....", "7--...", "8---..", "9----.", ":---...", ";-.-.-.",
 "< ", "=-...-", "> ", "?..--..", "@.--.-.","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()
{
}
void loop()
{
  char pointer=0;
  char pointer2=0;
  while (pointer2>=0)
  {
    if ((message[pointer2]>=' ')&&(message[pointer2]<='Z'))
    {
      unsigned char character=message[pointer2]-' ';
      pointer=0;
      while (pointer>=0)
      {
        switch(space_to_Z[character][pointer])
        {
          case '.':
            di();
            break;
          case '-':
            dah();
            break;
          case ' ':
            delay(6*period);
            break;
          case '':
            delay(2*period);
            pointer=-2;
            break;
          default :
            break;
        }
        pointer++;
      }     
    }
    else if (message[pointer2]=='') pointer2=-2;
    pointer2++;
  } 
} 

void di()
{
  analogWrite(buzzerPin, 2.5);
  delay(period);
  analogWrite(buzzerPin,0);
  delay(period);
}
void dah()
{
  analogWrite(buzzerPin, 2.5);
  delay(3*period);
  analogWrite(buzzerPin,0);
  delay(period);
}
 

2 Responses to Arduino project – Mores code generator

  1. rberk says:

    replace mores code with Morse code had to goto wikipedia for the capitalization. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: