March Madness - Morse Code Training |
This program USES the previous Morse Code library to offer training. It randomly sends a letter in morse code and you have to type it in. A space allows you to give up on it and it will display the morese code chart.
In doing this program I have enhanced the Morse Code library as well. Added a fucntion to get the text represntation of the code and a routine to print out the entire table.
Morse Code Trainer 0 _ _ _ _ _ @ . . . . . . P . _ _ . ! 1 . _ _ _ _ A . _ Q _ _ . _ " . _ . . _ . 2 . . _ _ _ B _ . . . R . _ . # 3 . . . _ _ C _ . _ . S . . . $ . . . _ . . _ 4 . . . . _ D _ . . T _ % 5 . . . . . E . U . . _ & 6 _ . . . . F . . _ . V . . . _ ' . _ _ _ _ . 7 _ _ . . . G _ _ . W . _ _ ( _ . _ _ . 8 _ _ _ . . H . . . . X _ . . _ ) _ . _ _ . _ 9 _ _ _ _ . I . . Y _ . _ _ * _ . . _ : _ _ _ . . . J . _ _ _ Z _ _ . . + . _ . _ . ; _ . _ . _ . K _ . _ [ _ . _ _ . , _ _ . . _ _ < _ . _ _ . L . _ . . \ - _ . . . . _ = _ . . . _ M _ _ ] _ . _ _ . _ . . _ . _ . _ > _ . _ _ . _ N _ . ^ / _ . . _ . ? . . _ _ . . O _ _ _ _ . . _ _ . _ ? = Help P = Practice T = Print Table ESC= Quite Practice |
|
|
//****************************************************************************
//* Morse code practice
#ifdef __MWERKS__
// int random(...);
#define PROGMEM
#define boolean char
#else
#endif
#include <MorseCode.h>
#include "HardwareSerial.h"
#define kPin_Buzzer 6
short gMode;
char gCurrentPracticeChar;
unsigned long gTimeOfLastCode;
int gTimesSent;
enum
{
kMode_Waiting = 0,
kMode_Practice,
kMode_Last
};
//****************************************************************************
void PrintHelp()
{
Serial.println("? = Help");
Serial.println("P = Practice");
Serial.println("T = Print Table");
Serial.println("ESC= Quite Practice");
}
//****************************************************************************
void Waiting(char theChar)
{
switch(theChar)
{
case '?':
PrintHelp();
break;
case 'P':
gMode = kMode_Practice;
gTimesSent = 0;
break;
case 'T':
DisplayMorseCodeTable();
break;
}
}
//****************************************************************************
void Practice(char theChar)
{
if (theChar == 0x1b)
{
gMode = kMode_Waiting;
Serial.println();
Serial.println("Exit practice mode");
}
else if (theChar == 0x20)
{
//* give up on this char
Serial.println(gCurrentPracticeChar);
gTimesSent = 0;
}
else if (theChar > 0)
{
//* the user typed a char, lets see if it matches
if (theChar == gCurrentPracticeChar)
{
//* we have a correct answer
Serial.print(theChar);
Serial.print(" ");
gTimesSent = 0;
}
}
if (gTimesSent == 0)
{
gCurrentPracticeChar = random(0x41, 0x5a);
SendMorseCode(gCurrentPracticeChar, 13, kPin_Buzzer);
gTimesSent++;
}
}
//****************************************************************************
void setup()
{
// SendMorseCodeString("Hello World", 13, kPin_Buzzer);
Serial.begin(9600);
Serial.println("Morse Code Trainer");
DisplayMorseCodeTable();
PrintHelp();
gCurrentPracticeChar = 0;
gMode = kMode_Waiting;
}
//****************************************************************************
void loop()
{
char theChar;
// when characters arrive over the serial port...
if (Serial.available())
{
theChar = Serial.read();
if (theChar > 0x5f)
{
theChar = theChar & 0x5f; //* force uper case
}
}
else
{
theChar = 0;
}
switch(gMode)
{
case kMode_Waiting:
Waiting(theChar);
break;
case kMode_Practice:
Practice(theChar);
break;
default:
break;
}
}
|
|
|
//#include <MorseCode.h>
#ifdef __cplusplus
extern "C" {
#endif
void SendMorseCode(char theChar, int wpm, int buzzerPinNum);
void SendMorseCodeString(char *theString, int wpm, int buzzerPinNum);
short GetMorseCodePattern(char theChar, char *codePattern);
void DisplayMorseCodeTable(void);
#ifdef __cplusplus
}
#endif
|
|
|
//************************************************************************ //* Morse code transmit //* //* This code is (C) by Mark Sproul //* //* This program is free software: you can redistribute it and/or modify //* it under the terms of the GNU General Public License as published by //* the Free Software Foundation, either version 3 of the License, or //* (at your option) any later version. //* //* This program is distributed in the hope that it will be useful, //* but WITHOUT ANY WARRANTY; without even the implied warranty of //* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //* GNU General Public License for more details. //* //************************************************************************ #ifdef __MWERKS__ #define PROGMEM short pgm_read_byte_near(...); #else #include |