Morse code Translator
Description¶
I will take a sentence from the serial com and later use the LEDs to output the same sentence using Morse code.
The Structure¶
Definition of variables¶
- Two variables
int
to define the LED output and the delay between the dots. - A list of
char
that will represent the letters from A-Z. - A list of
char
that represent the numbers from 0-9.
setup()
¶
The setup will contain the definition of the output pinMode()
and the baud for the serial communication.
loop()
¶
Here will be the main loop of the sketch.
- First, I create a
char
variable that holds a character. The character will come from the input, one character at a time. - I use the
Serial.available()
to check if something is waiting in the serial port. - It will read the serial input and save one character at a time in the variable
ch
. - A
if/else
conditionals that compare the input with letters (Arduino will read/interpret every letter as its value in ASCII). - Inside the
if/else
there is a functionflashSequence()
that will take as input one element of the listletters[]
, the element is selected by subtracting the ASCII value of the letter taken from the serial input and a letter of the alphabet[ch - 'a']
- A delay statement to make a gap between words (
delay(dotDelay * 4)
).
The functions¶
There will be two functions:
flashSequence()
: it is going to execute the flash sequence, and check if the is more sentence or words on the serial input.flashDotOrDash()
: is the function that will make the LED flash.