Advertisement
18107

Noteblock player

Jul 1st, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. --Piano player
  2. --version 1.0.1
  3. --Last updated 14 July 2015
  4. --For use with 'Computercraft nbs player' https://pastebin.com/0UZv2wUt
  5. --          or '18107's Jukebox' http://pastebin.com/B5dxWyxg
  6.  
  7. local modem = peripheral.find("modem")
  8. local event, temp, data
  9. local side = true
  10.  
  11. modem.open(1) --piano
  12. --[[
  13. 1 - piano
  14. 2 - double bass
  15. 3 - bass drum
  16. 4 - snare drum
  17. 5 - click
  18. ]]--
  19.  
  20. while true do
  21.   event, temp, temp, temp, data = os.pullEventRaw()
  22.   if event == "terminate" then
  23.     modem.closeAll()
  24.     return
  25.   end --if terminate
  26.  
  27.   if event == "modem_message" then
  28.     if side then
  29.       side = false
  30.       rs.setBundledOutput("front", bit.band(data, 4095))
  31.       rs.setBundledOutput("left", 0)
  32.       rs.setBundledOutput("back", bit.blogic_rshift(data, 12))
  33.       rs.setBundledOutput("right", 0)
  34.     else
  35.       side = true
  36.       rs.setBundledOutput("left", bit.band(data, 4095))
  37.       rs.setBundledOutput("front", 0)
  38.       rs.setBundledOutput("right", bit.blogic_rshift(data, 12))
  39.       rs.setBundledOutput("back", 0)
  40.     end --if side
  41.   end --if modem_message
  42. end --while all
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement