これは、モールス信号でのHelloWorldである。

Dependencies:   mbed

Committer:
gin_liquor
Date:
Wed Jan 08 04:11:49 2014 +0000
Revision:
0:ee17615ede36
????????????HelloWorld????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gin_liquor 0:ee17615ede36 1 #include "mbed.h"
gin_liquor 0:ee17615ede36 2 #include "morse.h"
gin_liquor 0:ee17615ede36 3
gin_liquor 0:ee17615ede36 4 char* mcode[] =
gin_liquor 0:ee17615ede36 5 {
gin_liquor 0:ee17615ede36 6 "a", "sl",
gin_liquor 0:ee17615ede36 7 "b", "lsss",
gin_liquor 0:ee17615ede36 8 "c", "lsls",
gin_liquor 0:ee17615ede36 9 "d", "lss",
gin_liquor 0:ee17615ede36 10 "e", "s",
gin_liquor 0:ee17615ede36 11 "f", "ssls",
gin_liquor 0:ee17615ede36 12 "g", "lls",
gin_liquor 0:ee17615ede36 13 "h", "ssss",
gin_liquor 0:ee17615ede36 14 "i", "ss",
gin_liquor 0:ee17615ede36 15 "j", "slll",
gin_liquor 0:ee17615ede36 16 "k", "lsl",
gin_liquor 0:ee17615ede36 17 "l", "slss",
gin_liquor 0:ee17615ede36 18 "m", "ll",
gin_liquor 0:ee17615ede36 19 "n", "ls",
gin_liquor 0:ee17615ede36 20 "o", "lll",
gin_liquor 0:ee17615ede36 21 "p", "slls",
gin_liquor 0:ee17615ede36 22 "q", "llsl",
gin_liquor 0:ee17615ede36 23 "r", "sls",
gin_liquor 0:ee17615ede36 24 "s", "sss",
gin_liquor 0:ee17615ede36 25 "t", "l",
gin_liquor 0:ee17615ede36 26 "u", "ssl",
gin_liquor 0:ee17615ede36 27 "v", "sssl",
gin_liquor 0:ee17615ede36 28 "w", "sll",
gin_liquor 0:ee17615ede36 29 "x", "lssl",
gin_liquor 0:ee17615ede36 30 "y", "lsll",
gin_liquor 0:ee17615ede36 31 "z", "llss",
gin_liquor 0:ee17615ede36 32 "1", "sllll",
gin_liquor 0:ee17615ede36 33 "2", "sslll",
gin_liquor 0:ee17615ede36 34 "3", "sssll",
gin_liquor 0:ee17615ede36 35 "4", "ssssl",
gin_liquor 0:ee17615ede36 36 "5", "sssss",
gin_liquor 0:ee17615ede36 37 "6", "lssss",
gin_liquor 0:ee17615ede36 38 "7", "llsss",
gin_liquor 0:ee17615ede36 39 "8", "lllss",
gin_liquor 0:ee17615ede36 40 "9", "lllls",
gin_liquor 0:ee17615ede36 41 "0", "lllll",
gin_liquor 0:ee17615ede36 42 ".", "slslsl",
gin_liquor 0:ee17615ede36 43 ",", "llssll",
gin_liquor 0:ee17615ede36 44 ":", "lllsss",
gin_liquor 0:ee17615ede36 45 "?", "ssllss",
gin_liquor 0:ee17615ede36 46 "\'", "slllls",
gin_liquor 0:ee17615ede36 47 "/", "lssls",
gin_liquor 0:ee17615ede36 48 "(", "lslls",
gin_liquor 0:ee17615ede36 49 ")", "lsllsl",
gin_liquor 0:ee17615ede36 50 "\"", "slssls",
gin_liquor 0:ee17615ede36 51 "-", "lssssl",
gin_liquor 0:ee17615ede36 52 "+", "slsls",
gin_liquor 0:ee17615ede36 53 "=", "lsssl",
gin_liquor 0:ee17615ede36 54 " ", "n",
gin_liquor 0:ee17615ede36 55 "*", "slsls",//end
gin_liquor 0:ee17615ede36 56
gin_liquor 0:ee17615ede36 57 "≤","sl",
gin_liquor 0:ee17615ede36 58 "€","slsl",
gin_liquor 0:ee17615ede36 59 " ","lsss",
gin_liquor 0:ee17615ede36 60 "∆","lsls",
gin_liquor 0:ee17615ede36 61 "Œ","lss",
gin_liquor 0:ee17615ede36 62 "Õ","s",
gin_liquor 0:ee17615ede36 63 "ƒ","sslss",
gin_liquor 0:ee17615ede36 64 "¡","ssls",
gin_liquor 0:ee17615ede36 65 "ÿ","lls",
gin_liquor 0:ee17615ede36 66 "«","ssss",
gin_liquor 0:ee17615ede36 67 "Ÿ","lslls",
gin_liquor 0:ee17615ede36 68 "¶","slll",
gin_liquor 0:ee17615ede36 69 "‹","lsl",
gin_liquor 0:ee17615ede36 70 "∂","slss",
gin_liquor 0:ee17615ede36 71 "÷","ll",
gin_liquor 0:ee17615ede36 72 "¿","ls",
gin_liquor 0:ee17615ede36 73 "⁄","lll",
gin_liquor 0:ee17615ede36 74 "ø","llls",
gin_liquor 0:ee17615ede36 75 "¬","slls",
gin_liquor 0:ee17615ede36 76 "»","llsl",
gin_liquor 0:ee17615ede36 77 "≈","sls",
gin_liquor 0:ee17615ede36 78 "◊","sss",
gin_liquor 0:ee17615ede36 79 "—","l",
gin_liquor 0:ee17615ede36 80 "≥","ssl",
gin_liquor 0:ee17615ede36 81 "$","slssl",//Éê
gin_liquor 0:ee17615ede36 82 "…","ssll",
gin_liquor 0:ee17615ede36 83 "µ","slsss",
gin_liquor 0:ee17615ede36 84 "∏","sssl",
gin_liquor 0:ee17615ede36 85 "‘","sll",
gin_liquor 0:ee17615ede36 86 "œ","lssl",
gin_liquor 0:ee17615ede36 87 "π","lsll",
gin_liquor 0:ee17615ede36 88 "Ã","llss",
gin_liquor 0:ee17615ede36 89 "∫","llll",
gin_liquor 0:ee17615ede36 90 "¥","lslll",
gin_liquor 0:ee17615ede36 91 "√","slsll",
gin_liquor 0:ee17615ede36 92 "±","llsll",
gin_liquor 0:ee17615ede36 93 "ª","lslsl",
gin_liquor 0:ee17615ede36 94 "∑","lslss",
gin_liquor 0:ee17615ede36 95 "’","lssll",
gin_liquor 0:ee17615ede36 96 "“","lsssl",
gin_liquor 0:ee17615ede36 97 "–","sslsl",
gin_liquor 0:ee17615ede36 98 "º","llsls",
gin_liquor 0:ee17615ede36 99 "|","sllss",//Éë
gin_liquor 0:ee17615ede36 100 "À","llssl",
gin_liquor 0:ee17615ede36 101 "”","lssls",
gin_liquor 0:ee17615ede36 102 "æ","sllls",
gin_liquor 0:ee17615ede36 103 "Ω","lllsl",
gin_liquor 0:ee17615ede36 104 "›","slsls",
gin_liquor 0:ee17615ede36 105 "fi","ss",
gin_liquor 0:ee17615ede36 106 "fl","sslls",
gin_liquor 0:ee17615ede36 107 "∞","sllsl",//cho-on
gin_liquor 0:ee17615ede36 108 "•","slslsl",//kugiri-ten
gin_liquor 0:ee17615ede36 109 "#","slslss",//danraku
gin_liquor 0:ee17615ede36 110 "¢","lsllsl",//kakko
gin_liquor 0:ee17615ede36 111 "£","slssls",//kakko-toji
gin_liquor 0:ee17615ede36 112 "^","sssls",//shushin
gin_liquor 0:ee17615ede36 113
gin_liquor 0:ee17615ede36 114 "\0", ""
gin_liquor 0:ee17615ede36 115 };
gin_liquor 0:ee17615ede36 116
gin_liquor 0:ee17615ede36 117 int getcode(int c)
gin_liquor 0:ee17615ede36 118 {
gin_liquor 0:ee17615ede36 119 for (int i = 0; mcode[i][0] != 0; i += 2) {
gin_liquor 0:ee17615ede36 120 if (mcode[i][0] == c) return i;
gin_liquor 0:ee17615ede36 121 }
gin_liquor 0:ee17615ede36 122 return -1;
gin_liquor 0:ee17615ede36 123 }
gin_liquor 0:ee17615ede36 124
gin_liquor 0:ee17615ede36 125 void putbeep(const char* str, int freq, int step)
gin_liquor 0:ee17615ede36 126 {
gin_liquor 0:ee17615ede36 127 //printf("%d:%s:%s\n", c, mcode[code], mcode[code + 1]);
gin_liquor 0:ee17615ede36 128 for (int i = 0; str[i] != '\0' && i < 1024; i++) {
gin_liquor 0:ee17615ede36 129 int c = getcode(str[i]);
gin_liquor 0:ee17615ede36 130 //printf("%c", mcode[c][0]);
gin_liquor 0:ee17615ede36 131 //put alphabet
gin_liquor 0:ee17615ede36 132 for (int k = 0; k < 10; ++k) {
gin_liquor 0:ee17615ede36 133 switch (mcode[c + 1][k]) {
gin_liquor 0:ee17615ede36 134 case 's':
gin_liquor 0:ee17615ede36 135 morsebeep(freq, step);
gin_liquor 0:ee17615ede36 136 morsewait(step);
gin_liquor 0:ee17615ede36 137 break;
gin_liquor 0:ee17615ede36 138 case 'l':
gin_liquor 0:ee17615ede36 139 morsebeep(freq, step * 3);
gin_liquor 0:ee17615ede36 140 morsewait(step);
gin_liquor 0:ee17615ede36 141 break;
gin_liquor 0:ee17615ede36 142 case 'n':
gin_liquor 0:ee17615ede36 143 morsewait(step * 6);
gin_liquor 0:ee17615ede36 144 break;
gin_liquor 0:ee17615ede36 145 case '_':
gin_liquor 0:ee17615ede36 146 morsewait(step * 2);
gin_liquor 0:ee17615ede36 147 break;
gin_liquor 0:ee17615ede36 148 case '\0':
gin_liquor 0:ee17615ede36 149 morsewait(step * 2);
gin_liquor 0:ee17615ede36 150 k = 10;
gin_liquor 0:ee17615ede36 151 break;
gin_liquor 0:ee17615ede36 152 }
gin_liquor 0:ee17615ede36 153 }
gin_liquor 0:ee17615ede36 154 }
gin_liquor 0:ee17615ede36 155 }