Advertisement
Laine_prikol

Opencomputers Note Sequencer

Mar 6th, 2017
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.42 KB | None | 0 0
  1. local term = require("term")
  2. local computer = require("computer")
  3. local keyboard = require("keyboard")
  4. currentNote = 0
  5. note1 = 0
  6. note2 = 0
  7. note3 = 0
  8. note4 = 0
  9. note5 = 0
  10. note6 = 0
  11. note7 = 0
  12. note8 = 0
  13. note9 = 0
  14. note10 = 0
  15. note1sec = 0
  16. note2sec = 0
  17. note3sec = 0
  18. note4sec = 0
  19. note5sec = 0
  20. note6sec = 0
  21. note7sec = 0
  22. note8sec = 0
  23. note9sec = 0
  24. note10sec = 0
  25. i = 0
  26. i2 = 0
  27. term.clear()
  28. function redrawMenu()
  29. term.clear()
  30. print("+-Note Sequencer-----------------+")
  31. print("+ 1-2-3-4-5-6-7-8-9 Играть ноты  +")
  32. print("+ F1-F10 - Настройка нот         +")
  33. print("+ Ctrl - Играть  Shift - Random  +")
  34. print("+ X - Выход                      +")
  35. print("+--------------------------------+")
  36. print("Сечас играет нота: "..currentNote)
  37. end
  38. redrawMenu()
  39. while true do
  40. os.sleep(0.1)
  41.     if keyboard.isKeyDown(0x3B) == true then -- f1
  42.     os.sleep(0.1)
  43.     print("Настройка ноты 1")
  44.     -- Чтение частоты
  45.     io.write("Частота: ")
  46.     note1 = io.read("*number")
  47.     print("Частота установлена на"..note1)
  48.     -- Чтение длительностей
  49.     io.write("Длительность (в секундах): ")
  50.     note1sec = io.read("*number")
  51.     print("Длительность установлена на"..note1sec)
  52.     redrawMenu()
  53.     end
  54. os.sleep(0.1)
  55.     if keyboard.isKeyDown(0x3C) == true then -- f2
  56.     os.sleep(0.1)
  57.     print("Настройка ноты 2")
  58.     -- Чтение частоты
  59.     io.write("Частота: ")
  60.     note2 = io.read("*number")
  61.     print("Частота установлена на"..note2)
  62.     -- Чтение длительностей
  63.     io.write("Длительность (в секундах): ")
  64.     note2sec = io.read("*number")
  65.     print("Длительность установлена на"..note2sec)
  66.     redrawMenu()
  67.     end
  68.     if keyboard.isKeyDown(0x3D) == true then -- f3
  69.     os.sleep(0.1)
  70.     print("Настройка ноты 3")
  71.     -- Чтение частоты
  72.     io.write("Частота: ")
  73.     note3 = io.read("*number")
  74.     print("Частота установлена на"..note3)
  75.     -- Чтение длительностей
  76.     io.write("Длительность (в секундах): ")
  77.     note3sec = io.read("*number")
  78.     print("Длительность установлена на"..note3sec)
  79.     redrawMenu()
  80.     end
  81.     if keyboard.isKeyDown(0x3E) == true then -- f4
  82.     os.sleep(0.1)
  83.     print("Настройка ноты 4")
  84.     -- Чтение частоты
  85.     io.write("Частота: ")
  86.     note4 = io.read("*number")
  87.     print("Частота установлена на"..note4)
  88.     -- Чтение длительностей
  89.     io.write("Длительность (в секундах): ")
  90.     note4sec = io.read("*number")
  91.     print("Длительность установлена на"..note4sec)
  92.     redrawMenu()
  93.     end
  94.     if keyboard.isKeyDown(0x3F) == true then -- f5
  95.     os.sleep(0.1)
  96.     print("Настройка ноты 5")
  97.     -- Чтение частоты
  98.     io.write("Частота: ")
  99.     note5 = io.read("*number")
  100.     print("Частота установлена на"..note5)
  101.     -- Чтение длительностей
  102.     io.write("Длительность (в секундах): ")
  103.     note5sec = io.read("*number")
  104.     print("Длительность установлена на"..note5sec)
  105.     redrawMenu()
  106.     end
  107.     if keyboard.isKeyDown(0x40) == true then -- f6
  108.     os.sleep(0.1)
  109.     print("Настройка ноты 6")
  110.     -- Чтение частоты
  111.     io.write("Частота: ")
  112.     note6 = io.read("*number")
  113.     print("Частота установлена на"..note6)
  114.     -- Чтение длительностей
  115.     io.write("Длительность (в секундах): ")
  116.     note6sec = io.read("*number")
  117.     print("Длительность установлена на"..note6sec)
  118.     redrawMenu()
  119.     end
  120.     if keyboard.isKeyDown(0x41) == true then -- f7
  121.     os.sleep(0.1)
  122.     print("Настройка ноты 7")
  123.     -- Чтение частоты
  124.     io.write("Частота: ")
  125.     note7 = io.read("*number")
  126.     print("Частота установлена на"..note7)
  127.     -- Чтение длительностей
  128.     io.write("Длительность (в секундах): ")
  129.     note7sec = io.read("*number")
  130.     print("Длительность установлена на"..note7sec)
  131.     redrawMenu()
  132.     end
  133.     if keyboard.isKeyDown(0x42) == true then -- f8
  134.     os.sleep(0.1)
  135.     print("Настройка ноты 8")
  136.     -- Чтение частоты
  137.     io.write("Частота: ")
  138.     note8 = io.read("*number")
  139.     print("Частота установлена на"..note8)
  140.     -- Чтение длительностей
  141.     io.write("Длительность (в секундах): ")
  142.     note8sec = io.read("*number")
  143.     print("Длительность установлена на"..note8sec)
  144.     redrawMenu()
  145.     end
  146.     if keyboard.isKeyDown(0x43) == true then -- f9
  147.     os.sleep(0.1)
  148.     print("Настройка ноты 9")
  149.     -- Чтение частоты
  150.     io.write("Частота: ")
  151.     note9 = io.read("*number")
  152.     print("Частота установлена на"..note9)
  153.     -- Чтение длительностей
  154.     io.write("Длительность (в секундах): ")
  155.     note9sec = io.read("*number")
  156.     print("Длительность установлена на"..note9sec)
  157.     redrawMenu()
  158.     end
  159.     if keyboard.isKeyDown(0x44) == true then -- f10
  160.     os.sleep(0.1)
  161.     print("Настройка ноты 10")
  162.     -- Чтение частоты
  163.     io.write("Частота: ")
  164.     note10 = io.read("*number")
  165.     print("Частота установлена на"..note10)
  166.     -- Чтение длительностей
  167.     io.write("Длительность (в секундах): ")
  168.     note10sec = io.read("*number")
  169.     print("Длительность установлена на"..note10sec)
  170.     redrawMenu()
  171.     end
  172.     os.sleep(0.1)
  173.     if keyboard.isKeyDown(0x02) == true then -- 1
  174.     os.sleep(0.1)
  175.     computer.beep(note1, note1sec)
  176.     end
  177.     if keyboard.isKeyDown(0x03) == true then -- 2
  178.     os.sleep(0.1)
  179.     computer.beep(note2, note2sec)
  180.     end
  181.     if keyboard.isKeyDown(0x04) == true then -- 3
  182.     os.sleep(0.1)
  183.     computer.beep(note3, note3sec)
  184.     end
  185.     if keyboard.isKeyDown(0x05) == true then -- 4
  186.     os.sleep(0.1)
  187.     computer.beep(note4, note4sec)
  188.     end
  189.     if keyboard.isKeyDown(0x06) == true then -- 5
  190.     os.sleep(0.1)
  191.     computer.beep(note5, note5sec)
  192.     end
  193.     if keyboard.isKeyDown(0x07) == true then -- 6
  194.     os.sleep(0.1)
  195.     computer.beep(note6, note6sec)
  196.     end
  197.     if keyboard.isKeyDown(0x08) == true then -- 7
  198.     os.sleep(0.1)
  199.     computer.beep(note7, note7sec)
  200.     end
  201.     if keyboard.isKeyDown(0x09) == true then -- 8
  202.     os.sleep(0.1)
  203.     computer.beep(note8, note8sec)
  204.     end
  205.     if keyboard.isKeyDown(0x0A) == true then -- 9
  206.     os.sleep(0.1)
  207.     computer.beep(note9, note9sec)
  208.     end
  209.     if keyboard.isKeyDown(0x0B) == true then -- 10
  210.     os.sleep(0.1)
  211.     computer.beep(note10, note10sec)
  212.     end
  213.     if keyboard.isKeyDown(0x2D) == true then -- Выход
  214.     os.sleep(0.1)
  215.     os.exit()
  216.     end
  217.     if keyboard.isShiftDown() == true then -- Рандом
  218.     computer.beep(1500, 0.5)
  219.     note1 = math.random(100, 2000)
  220.     note2 = math.random(100, 2000)
  221.     note3 = math.random(100, 2000)
  222.     note4 = math.random(100, 2000)
  223.     note5 = math.random(100, 2000)
  224.     note6 = math.random(100, 2000)
  225.     note7 = math.random(100, 2000)
  226.     note8 = math.random(100, 2000)
  227.     note9 = math.random(100, 2000)
  228.     note10 = math.random(100, 2000)
  229.     note1sec = 0.1
  230.     note2sec = 0.2
  231.     note3sec = 0.1
  232.     note4sec = 0.3
  233.     note5sec = 0.1
  234.     note6sec = 0.5
  235.     note7sec = 1
  236.     note8sec = 0.1
  237.     note9sec = 0.1
  238.     note10sec = 0.4
  239.     end
  240.     if keyboard.isControlDown() == true then -- Играть
  241.     io.write("Сколько раз повторять: ")
  242.     i2 = io.read("*number")
  243.     os.sleep(0.1)
  244.            for i = 1, i2 do
  245.             computer.beep(note1,note1sec)
  246.             currentNote = currentNote + 1
  247.             redrawMenu()
  248.             computer.beep(note2,note2sec)
  249.             currentNote = currentNote + 1
  250.             redrawMenu()
  251.             computer.beep(note3,note3sec)
  252.             currentNote = currentNote + 1
  253.             redrawMenu()
  254.             computer.beep(note4,note4sec)
  255.             currentNote = currentNote + 1
  256.             redrawMenu()
  257.             computer.beep(note5,note5sec)
  258.             currentNote = currentNote + 1
  259.             redrawMenu()
  260.             computer.beep(note6,note6sec)
  261.             currentNote = currentNote + 1
  262.             redrawMenu()
  263.             computer.beep(note7,note7sec)
  264.             currentNote = currentNote + 1
  265.             redrawMenu()
  266.             computer.beep(note8,note8sec)
  267.             currentNote = currentNote + 1
  268.             redrawMenu()
  269.             computer.beep(note9,note9sec)
  270.             currentNote = currentNote + 1
  271.             redrawMenu()
  272.             computer.beep(note10,note10sec)
  273.             currentNote = currentNote + 1
  274.             currentNote = 0
  275.             redrawMenu()
  276. end
  277. end
  278. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement