Advertisement
Guest User

Automatic Disc Changer API

a guest
Apr 5th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. -- Automatic Disc Changer API
  2. -- By David Findley
  3. -- 2013-04-05 (yyyy-mm-dd)
  4.  
  5. -- Lengths of all the vanilla discs.
  6. -- If you want to use non-vanilla discs
  7. -- then add the name and length here.
  8. local lengths = {["C418 - 13"]=180, ["C418 - cat"]=186, ["C418 - blocks"]=347, ["C418 - chirp"]=186, ["C418 - far"]=172, ["C418 - mall"]=197, ["C418 - mellohi"]=98, ["C418 - stal"]=151, ["C418 - strad"]=191, ["C418 - ward"]=250, ["C418 - 11"]=70}
  9.  
  10. -- Edit these values depending on your setup.
  11. -- If you use the setup I posted, then leave them.
  12. local loadS = "left"
  13. local ejectS = "back"
  14. local resetS = "top"
  15. local diskS = "bottom"
  16.  
  17. function reset()
  18.   for i=1,10 do
  19.     rs.setOutput(resetS, true)
  20.     sleep(0.1)
  21.     rs.setOutput(resetS, false)
  22.     sleep(0.1)
  23.   end
  24. end
  25.  
  26. function eject()
  27.   rs.setOutput(ejectS, true)
  28.   sleep(0.1)
  29.   rs.setOutput(ejectS, false)
  30. end
  31.  
  32. -- Loads a disk into the drive.
  33. -- Returns true if the disk has audio
  34. function load()
  35.   rs.setOutput(loadS, true)
  36.   sleep(0.1)
  37.   rs.setOutput(loadS, false)
  38.   sleep(0.5)
  39.   if (disk.hasAudio(diskS)) then
  40.     return true
  41.   else
  42.     return false
  43.   end
  44. end
  45.  
  46. -- Plays audio on the disk
  47. -- Returns the length of the song
  48. -- in seconds
  49. function play()
  50.   disk.playAudio(diskS)
  51.   local t = lengths[disk.getAudioTitle(diskS)]
  52.   return t
  53. end
  54.  
  55. -- Stop the music
  56. function stop()
  57.   disk.stopAudio(diskS)
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement