Advertisement
Skillkiller

Roter Alarm Knopf

Sep 3rd, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Variablen
  2. wModul = "bottom"
  3. zone = "Schlafzimmer"
  4. lamp = "left"
  5. --Code
  6. rednet.open(wModul)
  7. alarm = false
  8. header = "Roter Alarm - " .. zone
  9.  
  10.  
  11. function start()
  12.     dashboard("Ist gestoppt")
  13.     updateRedstone()
  14. end
  15.  
  16. function updateRedstone()
  17.     redstone.setOutput(lamp, alarm)
  18. end
  19.  
  20. function blink()
  21. while alarm do
  22.     rednet.broadcast("Red Light on ALL", "1900Light")
  23.     sleep(1)
  24.     rednet.broadcast("Red Light off ALL", "1900Light")
  25.     sleep(1)
  26. end
  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. term.setCursorPos(math.floor((maxX - string.len(text)) / 2),math.floor(maxY / 2) + 1)
  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.         rednet.broadcast("Alarm stop!", "1900Alarm")
  70.         rednet.broadcast("Roter Alarm wurde gestoppt. Von Zone: " .. zone, "1900Crit")
  71.         rednet.broadcast("Red Light off ALL", "1900Light")
  72.     else
  73.         alarm = true
  74.         dashboard("Alarm l\195\164uft")
  75.         updateRedstone()
  76.         rednet.broadcast("Alarm start!", "1900Alarm")
  77.         rednet.broadcast("Roter Alarm wurde ausgel\195\182st. Von Zone: " ..zone, "1900Crit")
  78.         parallel.waitForAny(signal, blink)
  79.     end
  80. else
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement