Generate Morse code using console text input and output to LED and speaker.

Dependencies:   4DGL-uLCD-SE PinDetect mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EncodeMorse.cpp Source File

EncodeMorse.cpp

00001 /*
00002 INTERNATIONAL MORSE CODE - recommended characters and spacing definitions from:
00003 http://www.itu.int/rec/R-REC-M.1677-1-200910-I/
00004 
00005 SPACING IMPLEMENTATION:
00006 dot = "dit" = [.] = 1
00007 dash = "dah" = [-] = 3
00008 Spacing within character = 0 (This is pre-inserted for characters in the switch statement below.)
00009 Spacing between letters = 000 (3 zeros; resolved in main.cpp)
00010 Spacing between words = 0000000 (7 zeros; defined with keyboard [Space] button)
00011 */
00012 
00013 static char* EncodeMorse(char character)
00014 {
00015     int ascii = character;  // char to int
00016 
00017     switch(ascii)
00018     {
00019         case 8:     return "101010101010101";   // [Backspace] (8 dots)
00020         case 32:    return "0000000";           // [Space]
00021         case 34:    return "10301010301";       // ["] (quotation mark)
00022         case 39:    return "10303030301";       // ['] (apostrophe)
00023         case 40:    return "301030301";         // [(]
00024         case 41:    return "30103030103";       // [)]
00025         case 43:    return "103010301";         // [+]
00026         case 44:    return "30301010303";       // [,] (comma)
00027         case 45:    return "30101010103";       // [-]
00028         case 46:    return "10301030103";       // [.] (period)
00029         case 47:    return "301010301";         // [/]
00030         case 48:    return "303030303";         // 0
00031         case 49:    return "103030303";         // 1
00032         case 50:    return "101030303";         // 2
00033         case 51:    return "101010303";         // 3
00034         case 52:    return "101010103";         // 4
00035         case 53:    return "101010101";         // 5
00036         case 54:    return "301010101";         // 6
00037         case 55:    return "303010101";         // 7
00038         case 56:    return "303030101";         // 8
00039         case 57:    return "303030301";         // 9
00040         case 58:    return "30303010101";       // [:] (colon)
00041         case 61:    return "301010103";         // [=]
00042         case 63:    return "10103030101";       // [?]
00043         case 64:    return "10303010301";       // [@]
00044         case 65: case 97:   return "103";       // A,a
00045         case 66: case 98:   return "3010101";   // B,b
00046         case 67: case 99:   return "3010301";   // C,c
00047         case 68: case 100:  return "30101";     // D,d
00048         case 69: case 101:  return "1";         // E,e
00049         case 70: case 102:  return "1010301";   // F,f
00050         case 71: case 103:  return "30301";     // G,g
00051         case 72: case 104:  return "1010101";   // H,h
00052         case 73: case 105:  return "101";       // I,i
00053         case 74: case 106:  return "1030303";   // J,j
00054         case 75: case 107:  return "30103";     // K,k
00055         case 76: case 108:  return "1030101";   // L,l
00056         case 77: case 109:  return "303";       // M,m
00057         case 78: case 110:  return "301";       // N,n
00058         case 79: case 111:  return "30303";     // O,o
00059         case 80: case 112:  return "1030301";   // P,p
00060         case 81: case 113:  return "3030103";   // Q,q
00061         case 82: case 114:  return "10301";     // R,r
00062         case 83: case 115:  return "10101";     // S,s
00063         case 84: case 116:  return "3";         // T,t
00064         case 85: case 117:  return "10103";     // U,u
00065         case 86: case 118:  return "1010103";   // V,v
00066         case 87: case 119:  return "10303";     // W,w
00067         case 88: case 120:  return "3010103";   // X,x (also use for multiplication sign)
00068         case 89: case 121:  return "3010303";   // Y,y
00069         case 90: case 122:  return "3030101";   // Z,z
00070         
00071         case 0:     return "-1";    // null (for debugging)
00072         case 10:    return "-1";    // newline (for debugging)
00073         
00074         default:    return "";
00075     }
00076 }