Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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}
- --config
- local side = "right"
- local ejectOutput = "bottom"
- local insertOutput = "left"
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- --show name and time left while playing
- function show(name, length, endTime)
- clear()
- print("Playing: ", name)
- local untilEnd = math.floor(endTime - os.clock())
- print("Time left: ", untilEnd, " seconds")
- end
- --start change function
- function change()
- print("inserting new random music disc..")
- --to eject music disc from disk drive
- redstone.setOutput(ejectOutput, true)
- sleep(1)
- redstone.setOutput(ejectOutput, false)
- while disk.isPresent(side) do
- clear()
- print("waiting for auto-eject..")
- sleep(1)
- end
- --to insert music disc to disk drive
- redstone.setOutput(insertOutput, true)
- sleep(1)
- redstone.setOutput(insertOutput, false)
- while disk.isPresent(side) do
- clear()
- print("waiting for disc..")
- sleep(1)
- end
- return
- end
- -- start work function
- function work()
- if disk.isPresent(side) then
- if disk.hasAudio(side) then
- local diskName = disk.getLabel(side)
- local diskLength = lengths[diskName]
- local timer = os.startTimer(diskLength)
- local endTime = os.clock() + diskLength
- show(diskName,diskLength,endTime)
- --start playing
- disk.playAudio(side)
- local tick = os.startTimer(1)
- while true do
- local evt, arg = os.pullEvent()
- if evt == "disk_eject" then
- print("disk was ejected")
- error("bye")
- end
- if evt == "timer" then
- if arg == timer then
- change()
- return
- end
- --end if arg timer
- end
- --end if evt timer
- if evt == "timer" then
- if arg == tick then
- show(diskName,diskLength,endTime)
- tick = os.startTimer(1)
- end
- end
- --end if evt tick
- if evt == "key" then
- if arg == keys.right then
- change()
- return
- end
- end
- end
- --end while
- else
- --else for disk.hasAudio()
- clear()
- print("this is not a music disc")
- sleep(1)
- end
- else
- --else for disk.isPresent()
- clear()
- print("nothing in disk drive")
- sleep(1)
- end
- end
- --end work function
- while true do
- work()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement