Conversor Morse C++

  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Conversor Morse C++ as PDF for free.

More details

  • Words: 429
  • Pages: 3
Conversor de Texto a C�digo Morse (C++)

16776960 16711680 3348860

1FEFF00

/* ** Text to Morse Code Converter ** ** Copyright (C) 2005 Ram�n E. Torres Salom�n */ #include <stdio.h> #include <string.h> #include #ifdef _MSC_VER #include <windows.h> #else #include <dos.h> #endif #define MORSE_BEEP_FREQ

800 // 0.8KHz

// Timers #define MORSE_DOT_TIME 70 #define MORSE_DASH_TIME 210 #define MORSE_CHARACTER_SEPARATION MORSE_DOT_TIME*3 #define MORSE_WORD_SEPARATION MORSE_DOT_TIME*7 // Functions prototipes void playsound(int note, int duration); void morse(char c); int main(void) { char buffer[256]; printf("Raymondjavaxx Text to Morse Code Converter\n"); printf("------------------------------------------\n"); printf("Type a text and press enter: "); gets(buffer); int x=0; while(buffer[x]) { if(buffer[x] == ' ') { printf("\n"); while(buffer[x] == ' ') x++; if(buffer[x] == NULL) break; #ifdef _MSC_VER Sleep(MORSE_WORD_SEPARATION); #else

delay(MORSE_WORD_SEPARATION); #endif } morse(buffer[x]); x++; } system("PAUSE"); return 0; } /********* * func: morse * desc: morse parsing function ********************************************/ void morse(char c) { char code[8] = {0}; switch(toupper(c)) { // Letter Morse case 'A': strcpy(code, case 'B': strcpy(code, case 'C': strcpy(code, case 'D': strcpy(code, case 'E': strcpy(code, case 'F': strcpy(code, case 'G': strcpy(code, case 'H': strcpy(code, case 'I': strcpy(code, case 'J': strcpy(code, case 'K': strcpy(code, case 'L': strcpy(code, case 'M': strcpy(code, case 'N': strcpy(code, case 'O': strcpy(code, case 'P': strcpy(code, case 'Q': strcpy(code, case 'R': strcpy(code, case 'S': strcpy(code, case 'T': strcpy(code, case 'U': strcpy(code, case 'V': strcpy(code, case 'W': strcpy(code, case 'X': strcpy(code, case 'Y': strcpy(code, case 'Z': strcpy(code,

".-"); break; "-..."); break; "-.-."); break; "-.."); break; "."); break; "..-."); break; "--."); break; "...."); break; ".."); break; "-.-."); break; "-.-"); break; ".-.."); break; "--"); break; "-."); break; "---"); break; ".--."); break; "--.-"); break; ".-."); break; "..."); break; "-"); break; "..-"); break; "...-"); break; ".--"); break; "-..-"); break; "-.--"); break; "--.."); break;

// Digit Morse case '0': strcpy(code, case '1': strcpy(code, case '2': strcpy(code, case '3': strcpy(code, case '4': strcpy(code, case '5': strcpy(code, case '6': strcpy(code, case '7': strcpy(code,

"-----"); ".----"); "..---"); "...--"); "....-"); "....."); "-...."); "--...");

break; break; break; break; break; break; break; break;

case '8': strcpy(code, "---.."); break; case '9': strcpy(code, "----."); break; // Others case '.': strcpy(code, ".-.-.-"); break; case ',': strcpy(code, "--..--"); break; case '?': strcpy(code, "..--.."); break; default: printf("[invalid character '%c']\n", c); break; } for(int i=0; i<8; i++) { if(code[i] == '-') { printf("%c", code[i]); playsound(MORSE_BEEP_FREQ, MORSE_DASH_TIME); } else if(code[i] == '.') { printf("%c", code[i]); playsound(MORSE_BEEP_FREQ, MORSE_DOT_TIME); } } }

printf("\n");

/********* * func: playsound * desc: play a note with pc internal speaker ********************************************/ void playsound(int note, int duration) { #ifdef _MSC_VER Beep(note, duration); Sleep(MORSE_CHARACTER_SEPARATION); #else sound(note); delay(duration); nosound(); delay(MORSE_CHARACTER_SEPARATION); #endif } El c�digo est� preparado para ser compilado en Turbo C++ o en Visual C++ 6.

Related Documents

Conversor Morse C++
May 2020 5
Conversor Ad
November 2019 22
Letter Morse
May 2020 3
Clave Morse
June 2020 9
Steve Morse Dixie Licks
December 2019 11