Advertisement
9551

Untitled

May 23rd, 2021 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | None | 0 0
  1. b = require("button")
  2. local arg = {...}
  3. local m = peripheral.wrap(arg[1])
  4. local s = peripheral.wrap(arg[2])
  5. volume = 1
  6. pitch = 0
  7. inst = "harp"
  8. m.clear()
  9. local function prints()
  10.     m.setBackgroundColor(colors.white)
  11.     m.setTextScale(1.5)
  12.     m.setTextColor(colors.black)
  13.     m.setCursorPos(2, 2)
  14.     m.write("volume:" .. " " .. (volume * 10) .. " ")
  15.     m.setCursorPos(8, 2)
  16.     m.setTextColor(colors.green)
  17.     m.write("\24")
  18.     m.setTextColor(colors.red)
  19.     m.setCursorPos(8, 3)
  20.     m.write("\25")
  21.     m.setTextColor(colors.black)
  22.  
  23.     m.setTextColor(colors.black)
  24.     m.setCursorPos(2, 5)
  25.     m.write("pitch:" .. "  " .. pitch .. " ")
  26.     m.setCursorPos(8, 5)
  27.     m.setTextColor(colors.green)
  28.     m.write("\24")
  29.     m.setTextColor(colors.red)
  30.     m.setCursorPos(8, 6)
  31.     m.write("\25")
  32.     m.setTextColor(colors.black)
  33. end
  34. local function printe()
  35.     m.setCursorPos(14, 2)
  36.     m.write("harp")
  37.     m.setCursorPos(14, 3)
  38.     m.write("bass")
  39.     m.setCursorPos(14, 4)
  40.     m.write("snare")
  41.     m.setCursorPos(14, 5)
  42.     m.write("hat")
  43.     m.setCursorPos(14, 6)
  44.     m.write("basedrum")
  45.     m.setCursorPos(14, 7)
  46.     m.write("flute")
  47.     m.setCursorPos(20, 2)
  48.     m.write("bell")
  49.     m.setCursorPos(20, 3)
  50.     m.write("chime")
  51.     m.setCursorPos(20, 4)
  52.     m.write("guitar")
  53.     m.setCursorPos(2, 7)
  54.     m.setBackgroundColor(colors.red)
  55.     m.write("run note..")
  56.     m.setBackgroundColor(colors.white)
  57. end
  58. prints()
  59. printe()
  60. local function touchIn(ins, x, y, l, out)
  61.     if b.button(ins, x, y, l, 1) == true then
  62.         inst = tostring(out)
  63.         printe()
  64.         m.setCursorPos(x, y)
  65.         m.setBackgroundColor(colors.blue)
  66.         m.write(tostring(inst))
  67.         m.setBackgroundColor(colors.white)
  68.     end
  69. end
  70. while true do
  71.     local x = {os.pullEvent("monitor_touch")}
  72.     touchIn(x, 14, 2, 4, "harp")
  73.     touchIn(x, 14, 3, 4, "bass")
  74.     touchIn(x, 14, 4, 5, "snare")
  75.     touchIn(x, 14, 5, 5, "hat")
  76.     touchIn(x, 14, 6, 8, "basedrum")
  77.     touchIn(x, 14, 7, 5, "flute")
  78.     touchIn(x, 20, 2, 4, "bell")
  79.     touchIn(x, 20, 3, 5, "chime")
  80.     touchIn(x, 20, 4, 6, "guitar")
  81.     if b.button(x, 8, 2, 1, 1) == true then
  82.         if volume <= 3 then
  83.             volume = volume + 0.1
  84.             prints()
  85.         end
  86.     elseif b.button(x, 8, 3, 1, 1) == true then
  87.         if volume > 0.2 then
  88.             volume = volume - 0.1
  89.             prints()
  90.         end
  91.     end
  92.     if b.button(x, 8, 5, 1, 1) == true then
  93.         if pitch < 24 then
  94.             pitch = pitch + 1
  95.             prints()
  96.         end
  97.     elseif b.button(x, 8, 6, 1, 1) == true then
  98.         if pitch > 0 then
  99.             pitch = pitch - 1
  100.             prints()
  101.         end
  102.     end
  103.     if b.button(x, 2, 7, 10, 1) then
  104.         s.playNote(inst, volume, pitch)
  105.     end
  106. end
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement