Advertisement
Ganeesya

chime

Jun 24th, 2015
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. function playSound( notes,sound,redstoneside )
  2.     local before = 0
  3.     write(redstoneside.." ")
  4.     for i, v in ipairs(notes) do
  5.         if sound.s[i] then
  6.             v.setPitch(sound.s[i])
  7.             before=sound.s[i]
  8.         else
  9.             v.setPitch(before)
  10.         end
  11.         write(before.." ")
  12.     end
  13.     write("\n")
  14.  
  15.     redstone.setOutput(redstoneside,not redstone.getOutput(redstoneside))
  16.    
  17.     return sound.w
  18. end
  19.  
  20. function playSounds(notes,song,redstoneside)
  21.     for i, v in ipairs(song) do
  22.         -- local timeID = os.startTimer(v.w)
  23.         sleep(playSound(notes,v,redstoneside))
  24.         -- while (timeID ~= os.pullEvent("timer")[2]) do
  25.         -- end
  26.     end
  27. end
  28.  
  29. local notes = {}
  30. local famima = { {w=0.2,s={13}}
  31.                 ,{w=0.2,s={9}}
  32.                 ,{w=0.2,s={4,1}}
  33.                 ,{w=0.2,s={9}}
  34.                 ,{w=0.2,s={11,8}}
  35.                 ,{w=0.2,s={16}}
  36.                 ,{w=0.4,s={4}}
  37.                 ,{w=0.2,s={11,4}}
  38.                 ,{w=0.2,s={13}}
  39.                 ,{w=0.2,s={11,4}}
  40.                 ,{w=0.2,s={4}}
  41.                 ,{w=0.2,s={9,1}}}
  42. local SIDE_LIST = {"left" , "right" , "front" , "back" , "bottom" , "top"}
  43. local redstoneside = 1
  44.  
  45. for i, v in pairs(peripheral.getNames()) do
  46.     if peripheral.getType(v) == "music" then
  47.         notes[#notes + 1] = peripheral.wrap(v)
  48.     end
  49. end
  50.  
  51.  
  52. while true do
  53.  
  54.     -----------------view---------------
  55.     term.clear()
  56.     term.setCursorPos(1, 1)
  57.     write(SIDE_LIST[redstoneside])
  58.     ------------------------------------
  59.  
  60.     local eve = {os.pullEvent()}
  61.  
  62.     if eve[1] == "key" and eve[2] == 200 then -- "up"
  63.         redstoneside = redstoneside - 1
  64.         if redstoneside < 1 then
  65.             redstoneside = #SIDE_LIST
  66.         end
  67.     end
  68.     if eve[1] == "key" and eve[2] == 208 then -- "down"
  69.         redstoneside = redstoneside + 1
  70.         if redstoneside > #SIDE_LIST then
  71.             redstoneside = 1
  72.         end
  73.     end
  74.  
  75.     if eve[1] == "redstone" then
  76.         playSounds(notes,famima,SIDE_LIST[redstoneside])
  77.     end
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement