ArduinoSOS

From arrizza.org wiki

Jump to navigation Jump to search
Previous ⇦ ArduinoSerialInput Arduino ⇫ Up ArduinoFastSquare ⇨ Next

Overview

This project takes the LED blinking to a whole new level!

It blinks out the Morse Code pattern for SOS, that is 3 dots, 3 dashes, 3 dots. see https://en.wikipedia.org/wiki/Morse_code for the full alphabet, letters, punctuation, etc.

Git repository

https://bitbucket.org/arrizza/arduinosos

git clone git@bitbucket.org:arrizza/arduinosos.git

Setup

The set up for this sketch is very similar to that for ArduinoLedBlink for the LED.

Main Loop

Most of the hard work is done by the helper functions.

First we set up some #defines for the various delays between the units in the code. The definitions here are nearly a direct copy from the descriptions in the wikipedia article

#define oneunit 100
#define threeunits (oneunit * 3)
#define unitgap oneunit
#define lettergap  threeunits
#define wordgap (oneunit * 7)

A dot then is simply the LED lit for a time length of one unit

void dot()
  {
  digitalWrite(13, HIGH);
  delay(oneunit);
  digitalWrite(13, LOW);
  }

And a dash is the LED lit for a time length of three units

void dash()
  {
  digitalWrite(13, HIGH);
  delay(threeunits);
  digitalWrite(13, LOW);
  }

From these we can define an "s"

  dot();
  delay(unitgap);
  dot();
  delay(unitgap);
  dot();

Note that we didn't put the inter-letter gap at the end here. We don't know if this "s" is the end of a word or just the end of the letter. We'll let the caller figure that out and do the correct delay there.

And an "o" is similar

  dash();
  delay(unitgap);
  dash();
  delay(unitgap);
  dash();

Using these last two functions, the main loop is very simple: call S O S followed by an inter-word gap.

  s();
  delay(lettergap);
  o();
  delay(lettergap);
  s();

  delay(wordgap);

Notes

A nice extension to this would be to merge ArduinoSerialInput with this sketch. The idea is that the user could send a text string, via the Serial Port to the Arduino, and this sketch translates that into Morse Code.

For example to say "please help!" and the Arduino would blink out the dots and dashes for "p" and then "l" etc. It would have to recognize " " as gaps between words, and that an exclamation mark "!" has a special Morse Code and so on.

The challenges there are to:

  • get all of the characters right
  • get all of the gaps right
  • figure out how to handle unknown ASCII characters? see http://www.asciitable.com/
Personal tools