Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function play(name)
- local dfpwm = require("cc.audio.dfpwm")
- local speaker = peripheral.find("speaker")
- local decoder = dfpwm.make_decoder()
- for chunk in io.lines("sound/"..name..".dfpwm", 16 * 1024) do
- local buffer = decoder(chunk)
- while not speaker.playAudio(buffer, 100) do
- os.pullEvent("speaker_audio_empty")
- end
- end
- end
- function display()
- local disp = peripheral.find("monitor")
- disp.setTextScale(0.5)
- disp.setBackgroundColor(colors.lightGray)
- disp.clear()
- local termPc = term.redirect(disp)
- term.redirect(termPc)
- while true do
- local id, mode = os.pullEvent("display")
- term.redirect(disp)
- count = 1
- while displayActive do
- paintutils.drawImage(paintutils.loadImage("bilder/plane.nfp"),1,1)
- if mode == "hoch" then
- paintutils.drawImage(paintutils.loadImage("bilder/hoch"..count..".nfp"),1,1)
- elseif mode == "runter" then
- paintutils.drawImage(paintutils.loadImage("bilder/runter"..count..".nfp"),1,1)
- end
- paintutils.drawImage(paintutils.loadImage("bilder/ebene"..currentLevel..".nfp"),1,1)
- count = (count % 5) + 1
- sleep(0.5)
- end
- paintutils.drawImage(paintutils.loadImage("bilder/plane.nfp"),1,1)
- if mode == "ooo" or mode == "techniker" then
- paintutils.drawImage(paintutils.loadImage("bilder/ooo.nfp"),1,1)
- else
- paintutils.drawImage(paintutils.loadImage("bilder/ebene"..currentLevel..".nfp"),1,1)
- end
- term.redirect(termPc)
- end
- end
- function control()
- peripheral.find("modem", rednet.open)
- while true do
- local id, number, typ = rednet.receive()
- if typ == "ankunft" then
- currentLevel = number
- displayActive = false
- play(number)
- elseif typ == "abfahrt" then
- play("tuer")
- elseif typ == "hoch" or typ == "runter" then
- currentLevel = number
- displayActive = true
- print("Aufzug faehrt los")
- os.queueEvent("display", typ)
- elseif typ == "stop" then
- currentLevel = number
- displayActive = false
- elseif typ == "status" then
- currentLevel = number
- elseif typ == "startup" then
- displayActive = false
- currentLevel = number
- print("Aufzug gestartet")
- os.queueEvent("display", typ)
- elseif typ == "ooo" then
- displayActive = false
- os.queueEvent("display", typ)
- play("ooo")
- elseif typ == "techniker" then
- displayActive = false
- os.queueEvent("display", typ)
- end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Warte auf Anweisungen des Zentralrechners")
- print("Lokale ID: "..os.getComputerID())
- displayActive = false
- currentLevel = -1
- parallel.waitForAny(control, display)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement