Advertisement
Muhi98

Controller

Apr 13th, 2021 (edited)
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. ON, OFF = 15, 0
  2. FUEL, TEMP, WASTE, ACTIVATE = "bottom", "top", "left", "right"
  3. currentStatus = OFF
  4. command = OFF
  5.  
  6. function check()
  7.     if
  8.     redstone.getAnalogInput(FUEL)   == ON or
  9.     redstone.getAnalogInput(TEMP)   == ON or
  10.     redstone.getAnalogInput(WASTE)  == ON or
  11.     command == OFF
  12.     then
  13.         return false
  14.     end
  15.     return true
  16. end
  17.  
  18. function update()
  19.     redstone.setAnalogOutput(ACTIVATE, currentStatus)
  20.    
  21. end
  22.  
  23. function statusToString(stat)
  24.     if stat == 15 then
  25.         return "ACTIVATED"
  26.     else
  27.         return "OK"
  28.     end
  29. end
  30.  
  31. function checkAllInputs()
  32.     return
  33.     redstone.getAnalogInput(FUEL),
  34.     redstone.getAnalogInput(TEMP),
  35.     redstone.getAnalogInput(WASTE)
  36. end
  37.  
  38. rednet.open("front")
  39.  
  40. while true do
  41.     term.clear()
  42.     term.setCursorPos(1,1)
  43.     print("CHANGE STATE (ON=1/OFF=2)")
  44.     print()
  45.     local f, t, w = checkAllInputs()
  46.     print("CURRENT STATUS   : " .. statusToString(currentStatus))
  47.     print("FUEL             : " .. statusToString(f))
  48.     print("TEMPERATURE      : " .. statusToString(t))
  49.     print("WASTE            : " .. statusToString(w))
  50.  
  51.     sendStr =
  52.     statusToString(currentStatus) .. ";" ..
  53.     statusToString(f) .. ";" ..
  54.     statusToString(t) .. ";" ..
  55.     statusToString(w)
  56.  
  57.  
  58.  
  59.     repeat
  60.         event, code, msg = os.pullEvent()--wait for event
  61.     until
  62.     (event == "char" and (code == "1" or code == "2")) or
  63.     event == "redstone" or
  64.     event == "rednet_message"
  65.  
  66.  
  67.     if event == "char" then
  68.         if code == "1" then
  69.             command = ON
  70.         else
  71.             command = OFF
  72.         end
  73.     elseif event == "rednet_message" then
  74.         if msg == "1" then
  75.             command = ON
  76.         else
  77.             command = OFF
  78.         end
  79.     end
  80.  
  81.     if check() then
  82.         currentStatus = ON
  83.     else
  84.         currentStatus = OFF
  85.     end
  86.  
  87.  
  88.     update()
  89.     rednet.broadcast(sendStr)
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement