Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local computer = require('computer')
- local term = require('term')
- local unicode = require('unicode')
- local duration = 0.1 --длительность точки
- local frequency = 1000 --частота
- tMorse = {
- {[' '] = ' '},
- {['.'] = '.-.-.-'},
- {[','] = '--..--'},
- {[':'] = '---...'},
- {[';'] = '-.-.-.'},
- {["'"] = '.----.'},
- {['"'] = '.-..-.'},
- {['/'] = '-..-.'},
- {['_'] = '..--.-'},
- {['='] = '-...-'},
- {['+'] = '.-.-.'},
- {['-'] = '-....-'},
- {['?'] = '..--..'},
- {['!'] = '-.-.--'},
- {['@'] = '.--.-.'},
- {['0'] = '-----'},
- {['1'] = '.----'},
- {['2'] = '..---'},
- {['3'] = '...--'},
- {['4'] = '....-'},
- {['5'] = '.....'},
- {['6'] = '-....'},
- {['7'] = '--...'},
- {['8'] = '---..'},
- {['9'] = '----.'},
- {['A'] = '.-'},
- {['B'] = '-...'},
- {['C'] = '-.-.'},
- {['D'] = '-..'},
- {['E'] = '.'},
- {['F'] = '..-.'},
- {['G'] = '--.'},
- {['H'] = '....'},
- {['I'] = '..'},
- {['J'] = '.---'},
- {['K'] = '-.-'},
- {['L'] = '.-..'},
- {['M'] = '--'},
- {['N'] = '-.'},
- {['O'] = '---'},
- {['P'] = '.--.'},
- {['Q'] = '--.-'},
- {['R'] = '.-.'},
- {['S'] = '...'},
- {['T'] = '-'},
- {['U'] = '..-'},
- {['V'] = '...-'},
- {['W'] = '.--'},
- {['X'] = '-..-'},
- {['Y'] = '-.--'},
- {['Z'] = '--..'},
- {['А'] = '.-'},
- {['Б'] = '-...'},
- {['В'] = '.--'},
- {['Г'] = '--.'},
- {['Д'] = '-..'},
- {['Е'] = '.'},
- {['Ж'] = '...-'},
- {['З'] = '--..'},
- {['И'] = '..'},
- {['Й'] = '.---'},
- {['К'] = '-.-'},
- {['Л'] = '.-..'},
- {['М'] = '--'},
- {['Н'] = '-.'},
- {['О'] = '---'},
- {['П'] = '.--.'},
- {['Р'] = '.-.'},
- {['С'] = '...'},
- {['Т'] = '-'},
- {['У'] = '..-'},
- {['Ф'] = '..-.'},
- {['Х'] = '....'},
- {['Ц'] = '-.-.'},
- {['Ч'] = '---.'},
- {['Ш'] = '----'},
- {['Щ'] = '--.-'},
- {['Ъ'] = '--.--'},
- {['Ы'] = '-.--'},
- {['Ь'] = '-..-'},
- {['Э'] = '..-..'},
- {['Ю'] = '..--'},
- {['Я'] = '.-.-'}
- }
- local function unserializer(tbl)
- for k, v in pairs(tbl) do
- return k, v
- end
- end
- function txt_to_morse(str, wrt) -- txt_to_morse(string[текст], boolean[вывод результата на экран])
- str = unicode.upper(str)
- for i = 1, unicode.len(str) do --проходимся по строке
- iString = unicode.sub(str, i, i)
- for j = 1, #tMorse do --проходимся по таблице символов
- index, code = unserializer(tMorse[j])
- if index == iString then
- if wrt == true then
- x, y = term.getCursor()
- term.clearLine()
- term.write(index..' '..code)
- term.setCursor(x, y)
- end
- for h = 1, unicode.len(code) do --проходимся по строке кода символа
- mBit = unicode.sub(code, h, h)
- if mBit == '.' then
- computer.beep(frequency, duration) --пикаем точку
- elseif mBit == '-' then
- computer.beep(frequency, duration*3) --пикаем тире
- elseif mBit == ' ' then
- os.sleep(duration*7) -- пробел
- end
- os.sleep(duration) --пробел между Морзе-битами
- end
- os.sleep(duration*3) --пробел между символами
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement