Advertisement
ozozx235

musikeyboard.lua

May 22nd, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 KB | None | 0 0
  1. os.loadAPI("buttonAPI")
  2. m = peripheral.wrap("top")
  3. m.clear()
  4. spk = peripheral.wrap("right")
  5. instlist = {"harp", "bass", "snare", "hat", "basedrum", "flute", "bell", "chime", "guitar", "xylophone", "iron_xylophone", "cow_bell", "didgeridoo", "bit", "banjo", "pling"}
  6. inst = 1
  7. function init()
  8.     buttonAPI.label(1,1,instlist[inst])
  9.     for i=0, 23 do
  10.         function funk()
  11.             playKey(i)
  12.             buttonAPI.flash(""..i)
  13.         end
  14.         func=funk
  15.         x=0
  16.         y=0
  17.         if i%2==0 then
  18.             x = 1+i+(i/2)
  19.             y = 2
  20.         else
  21.             x = i+(i/2)
  22.             y = 6
  23.         end
  24.         buttonAPI.setTable(""..i,func,x,x+1,y,y+2)
  25.     end
  26.     buttonAPI.setTable("ins",changeInst,37,39,2,8)
  27.     buttonAPI.screen()
  28. end
  29. function changeInst()
  30.     inst=inst+1
  31.     if inst>16 then
  32.         inst = 1
  33.     end
  34.     m.setCursorPos(1,1)
  35.     m.clearLine()
  36.     buttonAPI.label(1,1,instlist[inst])
  37.     buttonAPI.flash("ins")
  38. end
  39. function playKey(pitch)
  40.     spk.playNote(instlist[inst],1,pitch)
  41. end
  42.  
  43. function getClick()
  44. event, side, x,y = os.pullEvent("monitor_touch")
  45. buttonAPI.checkxy(x,y)
  46. end
  47.  
  48. init()
  49.  
  50. while true do
  51.     getClick()
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement