Arduino: construye traductores de Morse - como funciona
En este consejo práctico aprenderá cómo puede construir fácilmente un traductor Morse con su Arduino.
Crear traductores de Morse con Arduino: esto es necesario
En primer lugar, por supuesto, necesitas un Arduino.
- También debe obtener un timbre activo y un LED.
- Conecte el zumbador al pin 9 y el LED al pin 13.
Arduino: programa traductor Morse
Aquí hemos programado un pequeño código de muestra para usted, que puede usar. Simplemente cárguelo al Arduino e inicie el monitor en serie.
- #define debug true
- int ledPin = 13;
- int altavozPin = 9;
- int pitch1 = 140;
- int pitch2 = 140;
- punto int = 50;
- int dash = 3 * punto;
- Cadena morseATable [] = {".-", "-...", "-.-.", "- ..", ".", "..-.", "-.", ". ... ", " .. ", " .--- ", " _._ ", " .- .. ", " - ", " -. ", " --- ", " .-- . ", " --.- ", " .-. ", " ... ", " - ", " ..- ", " ...- ", " .-- ", " -..- ", " -.-- ", " - .. "};
- Cadena morseNTable [] = {"-----", ".----", "..---", "...--", "....-", "... .. ", " -.... ", " --... ", " --- .. ", " ----. "};
- configuración nula () {
- pinMode (ledPin, OUTPUT);
- pinMode (altavoz Pin, SALIDA);
- Serial.begin (9600);
- if (depuración) {
- Serial.println ( "\ ninicial");}
- }
- bucle vacío () {
- si (verdadero) {
- convert2Morse (Serial.readString ());
- }
- }
- void convert2Morse (mensaje de cadena) {
- for (int pos = 0; pos <message.length (); pos ++) {
- if (depuración) {
- Serial.print (message.charAt (pos));
- Serial.print ("");
- }
- if ((message.charAt (pos)> = 97) && (message.charAt (pos) <= 122)) {
- triturado (morseATable [message.charAt (POS) -97]);}
- if ((message.charAt (pos)> = 48) && (message.charAt (pos) <= 57)) {
- triturado (tabla morse [mensaje [pos] -48]);}
- if (message.charAt (pos) == 32) {
- morseLED ("");}
- if (depuración) {
- Serial.println ();
- }
- }}
- nulo morseLED (secuencia de cadenas) {
- for (int pos = 0; pos <secuencia.length (); pos ++) {
- FlashLED (sequence.charAt (pos));}
- retraso (2 * punto);
- }
- vacío flashLED (char dotOrDash) {
- if (depuración) {
- Serial.print (dotOrDash);}
- if (dotOrDash == 46) {
- digitalWrite (ledPin, HIGH);
- tono (altavoz Pin, tono1);
- retraso (punto);
- digitalWrite (ledPin, LOW);
- noTone (speakerPin);
- retraso (punto);
- } más if (dotOrDash == 45) {
- digitalWrite (ledPin, HIGH);
- tono (altavoz Pin, tono2);
- retardo (guión);
- digitalWrite (ledPin, LOW);
- noTone (speakerPin);
- retraso (punto);
- } más if (dotOrDash == 32) {
- retraso (punto);}
- }
En el siguiente consejo práctico, le mostraremos cómo puede usar un módulo GSM en el Arduino.