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.
Then, we need to teach to arduino how to pass all the letters and numbers to morse code, we will do this with the next codes called char. 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. Next we will do the void setup wich doesn't requieres too much far away from setting the ledPin as an output and making the Serial as everything important it's on the void loop.
Now we will put the void loop. Here we will call a custom code we will latelly create which we call "flashSequence" which will translate all the morse code into flashes for the LED. Here we will just make it interact with the console, reading all the letters and numbers we put there translated to morse code with char.
Lastly, we will make the commands wich we will call in the loop to run the command, the flashSequence and FlashDotOrDash. 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
Now, we will go right to the end of the code and we will add just two new lines to "flashDotOrDash". 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 (first calling the speakerPin made before and then adding the sound Hz, in our case 440), 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. With this, the buzzer will make sounds cordinated with the LED.