Arduino: costruisci traduttori Morse - come funziona
In questo suggerimento pratico imparerai come creare facilmente un traduttore Morse con il tuo Arduino.
Costruire traduttori Morse con Arduino: questo è necessario
Prima di tutto, ovviamente, hai bisogno di un Arduino.
- Dovresti anche ottenere un cicalino attivo e un LED.
- Collegare il buzzer al pin 9 e il LED al pin 13.
Arduino: programma traduttore Morse
Qui abbiamo programmato un piccolo codice di esempio per te, che puoi usare. Basta caricarlo su Arduino e avviare il monitor seriale.
- #define debug true
- int ledPin = 13;
- int speakerPin = 9;
- int pitch1 = 140;
- int pitch2 = 140;
- int dot = 50;
- int dash = 3 * punto;
- String morseATable [] = {".-", "-...", "-.-.", "- ..", ".", "..-.", "-.", ". ... ", " .. ", " .--- ", " _._ ", " .- .. ", " - ", " -. ", " --- ", " .-- . ", " --.- ", " .-. ", " ... ", " - ", " ..- ", " ...- ", " .-- ", " -..- ", " -.-- ", " - .. "};
- String morseNTable [] = {"-----", ".----", "..---", "...--", "....-", "... .. ", " -.... ", " --... ", " --- .. ", " ----. "};
- void setup () {
- pinMode (ledPin, OUTPUT);
- pinMode (speakerPin, OUTPUT);
- Serial.begin (9600);
- if (debug) {
- Serial.println ( "\ nStart");}
- }
- void loop () {
- if (true) {
- convert2Morse (Serial.readString ());
- }
- }
- void convert2Morse (messaggio String) {
- for (int pos = 0; pos <message.length (); pos ++) {
- if (debug) {
- Serial.print (message.charAt (pos));
- Serial.print ("");
- }
- if ((message.charAt (pos)> = 97) && (message.charAt (pos) <= 122)) {
- morseLED (morseATable [message.charAt (pos) -97]);}
- if ((message.charAt (pos)> = 48) && (message.charAt (pos) <= 57)) {
- morseLED (tabella morse [messaggio [pos] -48]);}
- if (message.charAt (pos) == 32) {
- morseLED ("");}
- if (debug) {
- Serial.println ();
- }
- }}
- void morseLED (sequenza di stringhe) {
- for (int pos = 0; pos <sequence.length (); pos ++) {
- FlashLED (sequence.charAt (pos));}
- ritardo (2 * punto);
- }
- void flashLED (char dotOrDash) {
- if (debug) {
- Serial.print (dotOrDash);}
- if (dotOrDash == 46) {
- digitalWrite (ledPin, HIGH);
- tono (speakerPin, pitch1);
- ritardo (dot);
- digitalWrite (ledPin, LOW);
- noTone (speakerPin);
- ritardo (dot);
- } else if (dotOrDash == 45) {
- digitalWrite (ledPin, HIGH);
- tono (speakerPin, pitch2);
- ritardo (trattino);
- digitalWrite (ledPin, LOW);
- noTone (speakerPin);
- ritardo (dot);
- } else if (dotOrDash == 32) {
- ritardo (dot);}
- }
Nel prossimo suggerimento pratico, ti mostreremo come è possibile utilizzare un modulo GSM su Arduino.