Encoding messsages, continuously written on serial terminal, in Morse code. Resulting code is played by a buzzer. Please, use local echo on terminal for more impressive experience. To verify coded messages, there are some app for smartphone.
Fork of Morse by
Morse.h@2:39d67345f7b3, 2018-02-03 (annotated)
- Committer:
- marcoperciavalle
- Date:
- Sat Feb 03 11:45:23 2018 +0000
- Revision:
- 2:39d67345f7b3
- Parent:
- 1:84ef66bf435d
Encoding messsages, continuously written on serial terminal, in Morse code. Resulting code is played by a buzzer. ; Please, use local echo on terminal for more impressive experience. To verify coded messages, there are some app for smartphone.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcoperciavalle | 2:39d67345f7b3 | 1 | /* |
marcoperciavalle | 2:39d67345f7b3 | 2 | INTERNATIONAL MORSE CODE - recommended characters and spacing definitions from: |
marcoperciavalle | 2:39d67345f7b3 | 3 | http://www.itu.int/rec/R-REC-M.1677-1-200910-I/ |
marcoperciavalle | 2:39d67345f7b3 | 4 | |
marcoperciavalle | 2:39d67345f7b3 | 5 | SPACING IMPLEMENTATION: |
marcoperciavalle | 2:39d67345f7b3 | 6 | dot = "dit" = [.] = 1 |
marcoperciavalle | 2:39d67345f7b3 | 7 | dash = "dah" = [-] = 3 |
marcoperciavalle | 2:39d67345f7b3 | 8 | Spacing within character = 0 (This is pre-inserted for characters in the switch statement below.) |
marcoperciavalle | 2:39d67345f7b3 | 9 | Spacing between letters = 000 (3 zeros; resolved in main.cpp) |
marcoperciavalle | 2:39d67345f7b3 | 10 | Spacing between words = 0000000 (7 zeros; defined with keyboard [Space] button) |
rominos2 | 1:84ef66bf435d | 11 | */ |
marcoperciavalle | 2:39d67345f7b3 | 12 | |
marcoperciavalle | 2:39d67345f7b3 | 13 | static char* EncodeMorse(char character) |
marcoperciavalle | 2:39d67345f7b3 | 14 | { |
marcoperciavalle | 2:39d67345f7b3 | 15 | int ascii = character; // char to int |
marcoperciavalle | 2:39d67345f7b3 | 16 | |
marcoperciavalle | 2:39d67345f7b3 | 17 | switch(ascii) |
marcoperciavalle | 2:39d67345f7b3 | 18 | { |
marcoperciavalle | 2:39d67345f7b3 | 19 | case 8: return "101010101010101"; // [Backspace] (8 dots) |
marcoperciavalle | 2:39d67345f7b3 | 20 | case 32: return "0000000"; // [Space] |
marcoperciavalle | 2:39d67345f7b3 | 21 | case 34: return "10301010301"; // ["] (quotation mark) |
marcoperciavalle | 2:39d67345f7b3 | 22 | case 39: return "10303030301"; // ['] (apostrophe) |
marcoperciavalle | 2:39d67345f7b3 | 23 | case 40: return "301030301"; // [(] |
marcoperciavalle | 2:39d67345f7b3 | 24 | case 41: return "30103030103"; // [)] |
marcoperciavalle | 2:39d67345f7b3 | 25 | case 43: return "103010301"; // [+] |
marcoperciavalle | 2:39d67345f7b3 | 26 | case 44: return "30301010303"; // [,] (comma) |
marcoperciavalle | 2:39d67345f7b3 | 27 | case 45: return "30101010103"; // [-] |
marcoperciavalle | 2:39d67345f7b3 | 28 | case 46: return "10301030103"; // [.] (period) |
marcoperciavalle | 2:39d67345f7b3 | 29 | case 47: return "301010301"; // [/] |
marcoperciavalle | 2:39d67345f7b3 | 30 | case 48: return "303030303"; // 0 |
marcoperciavalle | 2:39d67345f7b3 | 31 | case 49: return "103030303"; // 1 |
marcoperciavalle | 2:39d67345f7b3 | 32 | case 50: return "101030303"; // 2 |
marcoperciavalle | 2:39d67345f7b3 | 33 | case 51: return "101010303"; // 3 |
marcoperciavalle | 2:39d67345f7b3 | 34 | case 52: return "101010103"; // 4 |
marcoperciavalle | 2:39d67345f7b3 | 35 | case 53: return "101010101"; // 5 |
marcoperciavalle | 2:39d67345f7b3 | 36 | case 54: return "301010101"; // 6 |
marcoperciavalle | 2:39d67345f7b3 | 37 | case 55: return "303010101"; // 7 |
marcoperciavalle | 2:39d67345f7b3 | 38 | case 56: return "303030101"; // 8 |
marcoperciavalle | 2:39d67345f7b3 | 39 | case 57: return "303030301"; // 9 |
marcoperciavalle | 2:39d67345f7b3 | 40 | case 58: return "30303010101"; // [:] (colon) |
marcoperciavalle | 2:39d67345f7b3 | 41 | case 61: return "301010103"; // [=] |
marcoperciavalle | 2:39d67345f7b3 | 42 | case 63: return "10103030101"; // [?] |
marcoperciavalle | 2:39d67345f7b3 | 43 | case 64: return "10303010301"; // [@] |
marcoperciavalle | 2:39d67345f7b3 | 44 | case 65: case 97: return "103"; // A,a |
marcoperciavalle | 2:39d67345f7b3 | 45 | case 66: case 98: return "3010101"; // B,b |
marcoperciavalle | 2:39d67345f7b3 | 46 | case 67: case 99: return "3010301"; // C,c |
marcoperciavalle | 2:39d67345f7b3 | 47 | case 68: case 100: return "30101"; // D,d |
marcoperciavalle | 2:39d67345f7b3 | 48 | case 69: case 101: return "1"; // E,e |
marcoperciavalle | 2:39d67345f7b3 | 49 | case 70: case 102: return "1010301"; // F,f |
marcoperciavalle | 2:39d67345f7b3 | 50 | case 71: case 103: return "30301"; // G,g |
marcoperciavalle | 2:39d67345f7b3 | 51 | case 72: case 104: return "1010101"; // H,h |
marcoperciavalle | 2:39d67345f7b3 | 52 | case 73: case 105: return "101"; // I,i |
marcoperciavalle | 2:39d67345f7b3 | 53 | case 74: case 106: return "1030303"; // J,j |
marcoperciavalle | 2:39d67345f7b3 | 54 | case 75: case 107: return "30103"; // K,k |
marcoperciavalle | 2:39d67345f7b3 | 55 | case 76: case 108: return "1030101"; // L,l |
marcoperciavalle | 2:39d67345f7b3 | 56 | case 77: case 109: return "303"; // M,m |
marcoperciavalle | 2:39d67345f7b3 | 57 | case 78: case 110: return "301"; // N,n |
marcoperciavalle | 2:39d67345f7b3 | 58 | case 79: case 111: return "30303"; // O,o |
marcoperciavalle | 2:39d67345f7b3 | 59 | case 80: case 112: return "1030301"; // P,p |
marcoperciavalle | 2:39d67345f7b3 | 60 | case 81: case 113: return "3030103"; // Q,q |
marcoperciavalle | 2:39d67345f7b3 | 61 | case 82: case 114: return "10301"; // R,r |
marcoperciavalle | 2:39d67345f7b3 | 62 | case 83: case 115: return "10101"; // S,s |
marcoperciavalle | 2:39d67345f7b3 | 63 | case 84: case 116: return "3"; // T,t |
marcoperciavalle | 2:39d67345f7b3 | 64 | case 85: case 117: return "10103"; // U,u |
marcoperciavalle | 2:39d67345f7b3 | 65 | case 86: case 118: return "1010103"; // V,v |
marcoperciavalle | 2:39d67345f7b3 | 66 | case 87: case 119: return "10303"; // W,w |
marcoperciavalle | 2:39d67345f7b3 | 67 | case 88: case 120: return "3010103"; // X,x (also use for multiplication sign) |
marcoperciavalle | 2:39d67345f7b3 | 68 | case 89: case 121: return "3010303"; // Y,y |
marcoperciavalle | 2:39d67345f7b3 | 69 | case 90: case 122: return "3030101"; // Z,z |
rominos2 | 1:84ef66bf435d | 70 | |
marcoperciavalle | 2:39d67345f7b3 | 71 | case 0: return "-1"; // null (for debugging) |
marcoperciavalle | 2:39d67345f7b3 | 72 | case 10: return "-1"; // newline (for debugging) |
rominos2 | 1:84ef66bf435d | 73 | |
marcoperciavalle | 2:39d67345f7b3 | 74 | default: return ""; |
rominos2 | 1:84ef66bf435d | 75 | } |
marcoperciavalle | 2:39d67345f7b3 | 76 | } |