Easiest Morse Code Code?

Hello, this is my first time using any microcontroller. I have a maestro 24 and I’m trying to get channel 0 to flash a morse code sequence. I need the output to be ON (+5v) OFF (0v) in controlled, delayed fashion to send morse code.

I’m not sure what the code ‘servo servo’ does, but hacking together from other example scripts it does the job of turning the servo channel fully on and off. Below I have a working example of flashing the letter ‘X’ in morse code with an LED attached to the (-) and (S) terminals of the 0 servo channel.

My questions are simple. 1) is this the best, most efficient way to send ‘digital’ signals through the servo channels? i.e. is ‘servo servo’ the best way? 2) Is there a flat out better way you can think of send basically a TTL signal through the servo channels to send morse code?

Thanks for any insight,
-Adam

# Simple script in POLOLU Controller to flash X in morse code (-..-) in a loop.

begin #START THE CODE

#Dash - BEGIN
  1 1 8000 0 servo servo #LED ON
  500 delay #ON LENGTH
  0 0 0 0 servo servo #LED OFF
  150 delay #OFF LENGTH
#Dash - END

#Dot - BEGIN
  1 1 8000 0 servo servo #LED ON
  250 delay #ON LENGTH
  0 0 0 0 servo servo #LED OFF
  150 delay #OFF LENGTH
#Dot - END

#Dot - BEGIN
  1 1 8000 0 servo servo #LED ON
  250 delay #ON LENGTH
  0 0 0 0 servo servo #LED OFF
  150 delay #OFF LENGTH
#Dot - END

#Dash - BEGIN
  1 1 8000 0 servo servo #LED ON
  500 delay #ON LENGTH
  0 0 0 0 servo servo #LED OFF
  150 delay #OFF LENGTH
#Dash - END

#END of message - BEGIN
  0 0 0 0 servo servo #LED OFF
  1500 delay #OFF LENGTH
#END of message - END

repeat #REPEAT FROM THE START

Hello, Adam!

I am glad you were able to get this working. In the Channel Settings tab of the Maestro Control Center, be sure to configure Channel 0 as an “Output” instead of “Servo”; one of the effects of that is that the LED will be much brighter.

The code “servo servo” would simply call the “servo” command twice, so if you understand what the “servo” command does (i.e. what values it consumes from the stack and what it does with them) then it should be easy to understand what “servo servo” does. The “servo” command is documented in the Maestro User’s Guide in the chapter about the Maestro scripting language.

It looks like you are trying to set channel 1’s target to 1 occasionally. The number 1 is a not a valid value for a channel target and I don’t think you’re even using channel 1 so you can just replace those double servo commands with normal, single servo commands. You can also use subroutines in order to save program space and save typing. Here’s how I would have written your program:

begin
  x message_end
repeat

sub morse_led_on
  8000 0 servo
  return

sub morse_led_off
  4000 0 servo
  return

sub dash
  morse_led_on
  500 delay
  morse_led_off
  150 delay
  return

sub dot
  morse_led_on
  250 delay
  morse_led_off
  150 delay
  return

sub message_end
  1500 delay
  return

sub x  dash dot dot dash  return

This should be much easier to maintain over time.

–David

Thanks David! This is much more concise and useful. I’m understanding the coding language better too. I’ll keep working at it. I want to get to a point where I can send whole sentences to be converted into morse code. I’m thinking I’ll need to get some C# or .NET programming for that task.
-Adam

If there aren’t too many sentences you could just store them in your Maestro as different subroutines. The subroutines would look like this:

–David