Monday, 25 November 2013

Send morse messages from KB

There is an Arduino library called MorseEnDecoder.h which can be used for encoding characters and send them as morse code at a fixed WPM. It can also be used for decoding received morse (but at a fixed WPM...).

The output of the program is a TTL signal an Arduino pin. This must be used to drive an external oscillator if audio is required, it can drive a relay directly to key a transmitter if no local audio is required - or it could do both!

The oscillator circuit uses a TTL 74LS00:

2013 11 25 17 56 33

Here's the code:

// sends TTL signal on OSCPIN to a TTL external osillator
// input from Serial Monitor, "string_to_send CR"

#include "avr/pgmspace.h"
#include "MorseEnDecoder.h"

#define WPM 5

#define OSCPIN 7

// morseOut class
morseEncoder morseOut(OSCPIN);

// timing
long lastTrans;
long current;
boolean ended = true;

void setup() {
  
  pinMode(OSCPIN, OUTPUT);
  
  Serial.begin(9600);
  
  morseOut.setspeed(WPM);
  
  lastTrans = millis();
}

void loop() {
  
  current = millis();
  
  morseOut.encode(); // must call once per loop
  
  if(Serial.available() && morseOut.available()) {
    char letter = Serial.read(); // read the next letter
    morseOut.write(letter); // send the letter
  }
  
  if(!morseOut.available()) {
    lastTrans = current;
    ended = false;
  }
}

No comments: