// ************************************************************************************************
//
// Documentation for this, and the rest of the LC libraries that make this up.
// Here's the book : https://github.com/leftCoast/LC_libraryDocs/blob/main/LC_libraries.pdf
// libraries used : LC_baseTools
//
// That should keep you busy.
//
// ************************************************************************************************
#include <strTools.h>
#include <serialStr.h>
#include "morseCode.h"
serialStr serialMgr; // Bring in complete strings. While you do other things.
letter codeReader; // Will type out a letter in morse code. While you do other things.
char* ourText; // The string we'll be working on to tap out.
int numChars; // The number of chars we're currently working on.
int strIndex; // The actual letter we're sending out.
void setup(void) {
Serial.begin(115200); // Serial bla bla bla..
Serial.println("Type a string, hear the morse code version."); // Tell the user what we're up to.
serialMgr.setCallback(incoming); // Setup a function to recieve the string from the user.
codeReader.setCallback(doKey); // Setup a function to beep when the key is down.
ourText = NULL; // Always start pointers at NULL. Don't argue!
numChars = 0; // None yet.
strIndex = 0; // First char.
}
// This callback will be called when it's time to tap or release the morse key.
void doKey(bool down) {
if (down) { // If it's down?
tone(2,600); // We beep.
} else { // Else..
noTone(2); // We shut up.
}
}
// This callback recieves the user strings.
void incoming(const char* newStr) {
if (codeReader.letterDone()) { // If we ain't working on something at the moment..
heapStr(&ourText,newStr); // Copy the string we got. (Save it for now)
numChars = strlen(newStr); // Count the chars for later.
strIndex = 0; // We start at zero. Duh!
} else { // ELse we're working on a string already?
Serial.println("Wait a bit, not done yet."); // Tell the user to wait a bit.
} //
}
void loop(void) {
idle(); // idle() runs all the magic behind the curtain.
if (codeReader.letterDone()) { // If we're waiting for the next letter..
if (numChars>0 && strIndex < numChars) { // We got a string and we ain't done with it yet..
if (ourText[strIndex]!='\0') { // We're not looing at the end of the string..
codeReader.setLetter(ourText[strIndex]); // Stuff in this char to be tapped out.
strIndex++; // Bump up the index for the next time we're board.
} else { // Else we ran out of string?
strIndex = 0; // Reset the index for the next one.
numChars = 0; // Again, we got no chars.
} //
} //
} //
}