Here I will talk about the second part of our project, taken after setting everything up and making the SOS code (explained in my web)
Here we made the entire morse alphabet, which I will explain how it works, and also configurated in it to make a buzzer do sounds as the LED lights on. All this being able to writting anything (letters A-Z and numbers) in the console, and the code transforming it into morse code
This is the code we used still without the buzzer explained in parts:
First, we will seet the pin of our led using ledPin and we will also create a word to be the value of the delay requiered for the led to work well, the recommended for this it's 200.
Here we will put in alphabetical order every single word and number in morse code, so when we will put these, arduino will read it in morse code.
Now we will put the void loop.
The flashSequence it's simple, which will just call the flashDotOrDash and add a bit of the firstly created delay to make the sound not collapse. Now, the flashDotOrDash it's the important one, this one it's the one that will transfor every single dot or dash given by the translated console letters and numbers, into LED flashes, being the dash a long flash and the dot a short flash, adding some delay between them to give the message clear
Now, to end this morse project we made all this code to also run with a buzzer, doing the same as the LED but with sounds using tone. This could look a bit hard but in fact, it is quite simple. We first will need to set the speakerPin with int right at the start, change the number depending of where you connect it, and connect the other cable in the GBR port of the chip
As I said, flashDotOrDash reads the dots and dashes given and makes them to do LED flashes, so for making the buzzer sound we will just say to the flashDotOrDash to also make a tune, which is the command to make a sound with a buzzer, setting the right configuration , so it will make a sound at the same moment as the LED turns on. Then, to make it stop making the sound we just add a noTone right at the same spot as the command that sets off the LED.