Created
June 5, 2015 18:00
-
-
Save nvsofts/bafec93dee2cf24f6fe0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 1s: 2000000くらい | |
| morse = {} | |
| morse["a"] = ".-" | |
| morse["b"] = "-..." | |
| morse["c"] = "-.-." | |
| morse["d"] = "-.." | |
| morse["e"] = "." | |
| morse["f"] = "..-." | |
| morse["g"] = "--." | |
| morse["h"] = "...." | |
| morse["i"] = ".." | |
| morse["j"] = ".---" | |
| morse["k"] = "-.-" | |
| morse["l"] = ".-.." | |
| morse["m"] = "--" | |
| morse["n"] = "-." | |
| morse["o"] = "---" | |
| morse["p"] = ".--." | |
| morse["q"] = "--.-" | |
| morse["r"] = ".-." | |
| morse["s"] = "..." | |
| morse["t"] = "-" | |
| morse["u"] = "..-" | |
| morse["v"] = "...-" | |
| morse["w"] = ".--" | |
| morse["x"] = "-..-" | |
| morse["y"] = "-.--" | |
| morse["z"] = "--.." | |
| morse["1"] = ".----" | |
| morse["2"] = "..---" | |
| morse["3"] = "...--" | |
| morse["4"] = "....-" | |
| morse["5"] = "....." | |
| morse["6"] = "-...." | |
| morse["7"] = "--..." | |
| morse["8"] = "---.." | |
| morse["9"] = "----." | |
| morse["0"] = "-----" | |
| kbd, err = rt.hw.open("keyboard1") | |
| bz, err2 = rt.hw.open("buzzer1") | |
| if not kbd then | |
| print(err) | |
| os.exit(1) | |
| end | |
| if not bz then | |
| print(err2) | |
| os.exit(1) | |
| end | |
| data = kbd:gets() | |
| for i = 1, string.len(data) do | |
| ch = string.sub(data, i, i) | |
| if ch == " " then | |
| for k = 1, 1400000 do | |
| end | |
| else | |
| ms = morse[ch] | |
| for j = 1, string.len(ms) do | |
| m = string.sub(ms, j, j) | |
| if m == "." then | |
| bz:tone("B4") | |
| for k = 1, 150000 do | |
| end | |
| bz:off() | |
| else | |
| bz:tone("B4") | |
| for k = 1, 450000 do | |
| end | |
| bz:off() | |
| end | |
| for k = 1, 150000 do | |
| end | |
| end | |
| for k = 1, 300000 do | |
| end | |
| end | |
| end | |
| kbd:close() | |
| bz:off() | |
| bz:close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment