SHOW:
|
|
- or go back to the newest paste.
| 1 | --Variablen | |
| 2 | wModul = "bottom" | |
| 3 | zone = "Schlafzimmer" | |
| 4 | - | lamp = "right" |
| 4 | + | lamp = "left" |
| 5 | --Code | |
| 6 | rednet.open(wModul) | |
| 7 | - | open = true |
| 7 | + | alarm = false |
| 8 | - | header = zone |
| 8 | + | header = "Roter Alarm - " .. zone |
| 9 | ||
| 10 | ||
| 11 | function start() | |
| 12 | - | rednet.broadcast(zone .. " status?", "1900Door") |
| 12 | + | dashboard("Ist gestoppt")
|
| 13 | - | senderId = rednet.receive("1900Door",3)
|
| 13 | + | updateRedstone() |
| 14 | - | if (open == true) then |
| 14 | + | |
| 15 | - | dashboard("Zimmer offen", senderId)
|
| 15 | + | |
| 16 | - | else |
| 16 | + | |
| 17 | - | dashboard("Derzeit geschlossen", senderId)
|
| 17 | + | redstone.setOutput(lamp, alarm) |
| 18 | end | |
| 19 | - | updateRedstone() |
| 19 | + | |
| 20 | function blink() | |
| 21 | while alarm do | |
| 22 | rednet.broadcast("Red Light on ALL", "1900Light")
| |
| 23 | - | if (open == true) then |
| 23 | + | sleep(1) |
| 24 | - | redstone.setOutput(lamp, true) |
| 24 | + | rednet.broadcast("Red Light off ALL", "1900Light")
|
| 25 | sleep(1) | |
| 26 | - | redstone.setOutput(lamp,false) |
| 26 | + | |
| 27 | end | |
| 28 | ||
| 29 | function dashboard(status, id) | |
| 30 | shell.run("clear")
| |
| 31 | maxX, maxY = term.getSize() | |
| 32 | term.setCursorPos(1,2) | |
| 33 | text = "" | |
| 34 | for i = 0, maxX - 1, 1 do | |
| 35 | text = text .. "#" | |
| 36 | end | |
| 37 | print(text) | |
| 38 | ||
| 39 | term.setCursorPos(math.floor((maxX - string.len(header)) / 2), 4) | |
| 40 | print(header) | |
| 41 | ||
| 42 | term.setCursorPos(math.floor((maxX - string.len(status)) / 2),math.floor(maxY / 2)) | |
| 43 | print(status) | |
| 44 | ||
| 45 | text = "" | |
| 46 | text = "Sende Befehle f\195\188r den Roten Alarm" | |
| 47 | - | text = "Sende Befehle an den Computer " .. tostring(id) |
| 47 | + | |
| 48 | print(text) | |
| 49 | ||
| 50 | text = "" | |
| 51 | term.setCursorPos(1,maxY) | |
| 52 | for i = 0, maxX - 1, 1 do | |
| 53 | text = text .. "#" | |
| 54 | end | |
| 55 | print(text) | |
| 56 | ||
| 57 | warten = " Signal kann gesendet werden " | |
| 58 | term.setCursorPos(math.floor((maxX - string.len(warten)) / 2),maxY - 1) | |
| 59 | print(warten) | |
| 60 | end | |
| 61 | ||
| 62 | function check() | |
| 63 | if rs.getInput("top") == true then
| |
| 64 | sleep(1) | |
| 65 | if (alarm == true) then | |
| 66 | alarm = false | |
| 67 | dashboard("Ist gestoppt")
| |
| 68 | updateRedstone() | |
| 69 | - | if rs.getInput("top") then
|
| 69 | + | rednet.broadcast("Alarm stop!", "1900Alarm")
|
| 70 | - | rednet.send(senderId, zone .. " status?", "1900Door") |
| 70 | + | rednet.broadcast("Roter Alarm wurde gestoppt. Von Zone: " .. zone, "1900Crit")
|
| 71 | - | senderId, message, protocol = rednet.receive("1900Door",3)
|
| 71 | + | rednet.broadcast("Red Light off ALL", "1900Light")
|
| 72 | - | if (message == true) then |
| 72 | + | else |
| 73 | - | rednet.send(senderId, zone .. " zu", "1900Door") |
| 73 | + | alarm = true |
| 74 | - | open = false |
| 74 | + | dashboard("Alarm l\195\164uft")
|
| 75 | updateRedstone() | |
| 76 | - | rednet.broadcast("Die T\195\188r " .. zone .. " wurde geschlossen", "1900Info")
|
| 76 | + | rednet.broadcast("Alarm start!", "1900Alarm")
|
| 77 | - | elseif (message == false) then |
| 77 | + | rednet.broadcast("Roter Alarm wurde ausgel\195\182st. Von Zone: " ..zone, "1900Crit")
|
| 78 | - | rednet.send(senderId, zone .. " auf", "1900Door") |
| 78 | + | parallel.waitForAny(signal, blink) |
| 79 | - | open = true |
| 79 | + | |
| 80 | else | |
| 81 | - | rednet.broadcast("Die T\195\188r f\195\188r " .. zone .. " wurde ge\195\182ffnet", "1900Info")
|
| 81 | + | print("Redstone changed")
|
| 82 | end | |
| 83 | end | |
| 84 | ||
| 85 | function signal() | |
| 86 | local event = os.pullEvent("redstone")
| |
| 87 | check() | |
| 88 | end | |
| 89 | ||
| 90 | --Einmalig alles Updaten | |
| 91 | start() | |
| 92 | ||
| 93 | --Endlosschleife | |
| 94 | while true do | |
| 95 | signal() | |
| 96 | end |