Into this section it is explained with the functioning of the ESP-8266-MOD to do SOS Morse Code with a Buzzer.
In the next video it is the siimulation of the SOS code made at Trinkercad with a Buzzer.
1 /* Created on 2022 2 * Last modification: 21st April 2022 3 * by Villares 4 */ 5 6 const int pinBuzzer = 5; // Buzzer connected to pin number 5 7 8 void setup() { // the setup routine runs once when you press reset
9 pinMode(pinBuzzer, OUTPUT); // Configures BUZZER pin to behave as an output
10 }
11
12 void SOS(int n) { // the SOS function is created, substituting the value n we can create 3 dots (S) or 3 dashes (O)
13 tone(pinBuzzer, 440); // turn the Buzzer on at a frequency of 440 Hz
14 delay(n); // wait for n seconds
15
16 noTone(pinBuzzer); // turn the Buzzer off
17 delay(500); // wait for n seconds
18
19 tone(pinBuzzer, 440);
20 delay(n);
21
22 noTone(pinBuzzer);
23 delay(500);
24
25 tone(pinBuzzer, 440);
26 delay(n);
27
28 noTone(pinBuzzer);
29 delay(1500); // space between letters is three units
30 }
31
32 void silence() { // the silence function is created for the space between words
33 noTone(pinBuzzer);
34 delay(2000); // space between words is seven units (in the SOS function there are already 3 units, so this delay is for 4 units)
35 }
36
37 void loop() { // the loop routine runs over and over again forever
38 SOS(500); // for the SOS function, we substitute the value n per 0.5s--> 3 dots
39 SOS(1500); // for the SOS function, we substitute the value n per 1.5s--> 3 dashes
40 SOS(500); // for the SOS function, we substitute the value n per 0.5s--> 3 dots
41 silence(); // the silence function is called--> space between words is seven units
42 }
43