mattysmith22

Reactor Watchdog

May 29th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. RSide = "back"
  2.  
  3. RLamp = colors.yellow
  4. RAlarm = colors.magenta
  5. RReactor = colors.green
  6. RTemp = colors.red
  7. RReset = colors.black
  8. RAck = colors.cyan
  9. REnergy = colors.lime
  10.  
  11. monitor = peripheral.wrap("top")
  12. monitor.setTextScale(5)
  13.  
  14. currOut = 0
  15.  
  16. function onOut(color)
  17.     currOut = colors.combine(currOut, color)
  18.     redstone.setBundledOutput(RSide, currOut)
  19. end
  20.  
  21. function offOut(color)
  22.     currOut = colors.subtract(currOut, color)
  23.     redstone.setBundledOutput(RSide, currOut)
  24. end
  25.  
  26. function testIn(color)
  27.     local curr = redstone.getBundledInput(RSide)
  28.     return colors.test(curr, color)
  29. end
  30.  
  31. function tst()
  32.     monitor.setCursorPos(1,2)
  33.     monitor.write(currOut)
  34. end
  35.  
  36. function standbyState()
  37.     offOut(RReactor)
  38.     offOut(RLamp)
  39.     offOut(RAlarm)
  40.    
  41.     while true do
  42.         tst()
  43.         if testIn(REnergy) then
  44.             state = "running"
  45.             break
  46.         end
  47.         os.pullEvent("redstone")
  48.     end
  49. end
  50.  
  51. function runningState()
  52.     onOut(RReactor)
  53.     offOut(RLamp)
  54.     offOut(RAlarm)
  55.    
  56.     while true do
  57.         tst()
  58.         if not testIn(REnergy) then
  59.             state = "standby"
  60.             break
  61.         elseif testIn(RTemp) then
  62.             state = "error"
  63.             break
  64.         end
  65.         os.pullEvent("redstone")
  66.     end
  67. end
  68.  
  69. function errorState()
  70.     offOut(RReactor)
  71.     onOut(RLamp)
  72.     onOut(RAlarm)
  73.    
  74.     while true do
  75.         tst()
  76.         os.pullEvent("redstone")
  77.         if testIn(RReset) then
  78.             state = "standby"
  79.             break
  80.         elseif testIn(RAck) then
  81.             state = "ack"
  82.             break
  83.         end
  84.     end
  85. end
  86.  
  87. function ackState()
  88.     offOut(RReactor)
  89.     onOut(RLamp)
  90.     offOut(RAlarm)
  91.     while true do
  92.         tst()
  93.         if testIn(RReset) then
  94.             state = "standby"
  95.             break
  96.         end
  97.         os.pullEvent("redstone")
  98.     end
  99. end
  100.  
  101. state = ""
  102.  
  103. if testIn(RTemp) then
  104.     state = "alarm"
  105. else
  106.     if testIn(REnergy) then
  107.         state = "running"
  108.     else
  109.         state = "standby"
  110.     end
  111. end
  112.  
  113. while true do
  114.     monitor.clear()
  115.     monitor.setCursorPos(1,1)
  116.     monitor.write(state)
  117.     if state == "standby" then
  118.         standbyState()
  119.     elseif state == "running" then
  120.         runningState()
  121.     elseif state == "error" then
  122.         errorState()
  123.     elseif state == "ack" then
  124.         ackState()
  125.     end
  126. end
Add Comment
Please, Sign In to add comment