Morse code blinker

The microcontroller programming equivalent of “Hello World” seems to be “Blink the LED”.

After going through some of the example code for my Netduino, I decided to expand a bit on the LED examples and come up with a simple little program that would make the onboard LED blink out Morse code.

After a few hours of futzing around trying to figure out the C# syntax and the relevant parts of the .NET Micro Framework, I finally came up with something that works pretty well. I called it MorseBlinker.

One of the problems I ran into was .NET Micro Framework API changes between 4.2 (which is what I had installed) and 4.1 which is what the examples in the Getting Started with Netduino book are written for. Also, apparently there’s a big difference between “a” and ‘a’ in C# (although I imagine it’s probably the same in C too). 

The string is hard coded into the program, so if i want to change what the Netduino blinks, I have to change the string and redeploy the app, which isn’t too difficult. Timing is also hard coded too (in the dit variable which specifies the duration of a dit in milliseconds), so changing the speed it blinks at also requires the app to be rebuilt and redeployed.


using System;
using System.Threading;
using System.Collections;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace MorseBlinker
{
public class Program
{
private static void blinker(OutputPort p, string a)
{
// Make the LED blink a morse code string provided by a
// Change the duration of the blinking by adjusting the dit variable
int dit = 50;                    // dit length in milliseconds
int dah = dit * 3;                // dah length in milliseconds
int space = dit * 7;              // space length in milliseconds
foreach (char sym in a)
{
switch (sym)
{
case '.':
p.Write(true);
Thread.Sleep(dit);
p.Write(false);
Thread.Sleep(dit);
break;
case '-':
p.Write(true);
Thread.Sleep(dah);
p.Write(false);
Thread.Sleep(dit);
break;
case ' ':
p.Write(false);
Thread.Sleep(space);
break;
default:
break;
}
}
p.Write(false);
Thread.Sleep(dit * 3);    // space between characters
}
public static void Main()
{
// Text to Morse code conversion table
Hashtable morse = new Hashtable();
morse.Add('a', ".-");
morse.Add('b', "-...");
morse.Add('c', "-.-.");
morse.Add('d', "-..");
morse.Add('e', ".");
morse.Add('f', "..-.");
morse.Add('g', "--.");
morse.Add('h', "....");
morse.Add('i', "..");
morse.Add('j', ".---");
morse.Add('k', "-.-");
morse.Add('l', ".-..");
morse.Add('m', "--");
morse.Add('n', "-.");
morse.Add('o', "---");
morse.Add('p', ".--.");
morse.Add('q', "--.-");
morse.Add('r', ".-.");
morse.Add('s', "...");
morse.Add('t', "-");
morse.Add('u', "..-");
morse.Add('v', "...-");
morse.Add('w', ".--");
morse.Add('x', "-..-");
morse.Add('y', "-.--");
morse.Add('z', "--..");
morse.Add('0', "-----");
morse.Add('1', ".----");
morse.Add('2', "..---");
morse.Add('3', "...--");
morse.Add('4', "....-");
morse.Add('5', ".....");
morse.Add('6', "-....");
morse.Add('7', "--...");
morse.Add('8', "---..");
morse.Add('9', "----.");
morse.Add(' ', " ");
morse.Add('.', "·-·-·-");
morse.Add(',', "--..--");
morse.Add('?', "..--..");
morse.Add('!', "-.-.--");
morse.Add('/', "-..-.");
// Text to play in Morse code. Change this to whatever you want
string morseText = "ab4ug";
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
while (true) {
// go through all the characters in morseText
foreach (char c in morseText)
{
// Blink the character in Morse code
blinker(led, (string)morse[c.ToLower()]);
}
// Delay 1s before repeating the text
led.Write(false);
Thread.Sleep(1000);
}
}
}
}

You can check out the latest version over at Github.

For my next trick, I think I’ll try to make a speaker buzz at the same time as the light flashes.

Morse code ringtones and vibration patterns

Yesterday I discovered that I can make custom vibration notification patterns for people in my Contacts list.

On the Galaxy S2, select a contact, scroll down to Vibration Pattern tap it to bring up a list and hit the Create button. When you tap the center of the circle, a line starts to sweep around the circle and you just tap out the vibration pattern you want to create. I’ve used it to create some Morse code vibration patterns for a few people

While I was doing that, I figured why not do the same for ring tones! Using the text to CW converter at lcwo.net made it super easy. Enter your text, select the speed and tone to play it and it gives you a link where you can download an MP3 file to send to the phone to use as a ring tone.

Play / Pause  

Learn CW Online – LCWO.netText to Morse Converter

So now for a few people stored in my phone, I have call sign Morse code ring tones and vibration patterns set up.

Exploring Arduino

I found the Make Getting Started with Netduino kits on clearance at Radio Shack for $20, so I decided to pick one up (rescuing more clearance items). Figured it would be a good way for me to get my feet wet in the Arduino and microcontroller world.

A Make: Getting started with Netduino kit and a Netduino board

The board it self is pretty small, maybe a little smaller than 10x10cm.

A Netduino microcontroller board.  The board has the same form factor as an Arduino microcontroller board.

The kit contains everything you need for the basics like making LEDs blink, a little speaker, a little bread board for prototyping and even a servo motor.

A Netduino microcontroller board, bundle of connector wires, a red mini breadboard with some LEDs in it, a small push button, speaker, and a strip of resistors
Ziplock bags that contain a small servo motor

There’s even a MakerShield included for building your own Arduino shield.

Makershield prototyping board

I’ll have to deal with C# and .NET, but I don’t think it should be too difficult. I’m looking forward to learning and playing with it.

Dim sum food truck

I’ve often lamented about the lack of dim sum in Charleston, which considering the number of Chinese and Asian restaurants in the area, has always seemed to be a significant oversight.

Maybe that will change a little bit soon. During one of my quasi-regular visits to the Charleston Kickstarter page, I saw one for a dim sum food truck. Dim Sum Good Dumplings (DSGD) and a guy named Chad Moore is behind the effort. A little bit of a different take on dim sum, and one I would love to see succeed.

From the project status updates he’s been posting, it looks very promising. Hopefully he doesn’t get too creative trying to put a “Southern spin” on his creations.

Join me! Back this project and help make it happen!

Case of the missing charger

Just when I got the urge to start doing some more photography again, I discover that the battery charger for my Rebel XT has disappeared. I’ve been using my little Sony camera in the meantime, but it’s making me miss the flexibility of DSLR.

Phooey.

Now I have to remember where the last place I packed the camera to use was.