This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Xixili's profile picture

Improve monitor check speed

Started by Xixili, 21 April 2014 - 08:36 PM
Xixili #1
Posted 21 April 2014 - 10:36 PM
Hello everyone.

I wrote some code that shows information on a monitor about the reactor.

The information works but is it possible to improve the response time?

Now the information updates every second because of the os.reboot command.

Is it also possible if the computer gets a redstone pulse that it updates the status about it?

The code I have so far:


mon = peripheral.wrap("left")
local x = rs.testBundledInput("right", colors.white)
while x ~= banana do
white = rs.testBundledInput("right", colors.white)	-- Reactor Status  1208
orange = rs.testBundledInput("right", colors.orange) -- uranium inser 1201
black = rs.testBundledInput("right", colors.black)	 -- Coolant Insert 1200
red = rs.testBundledInput("right", colors.red)	 -- Alarm 1 alarm File
-- Chest Checks
cchest = rs.testBundledInput("back", colors. blue) -- Coolant Chest Status 1300
uchest = rs.testBundledInput("back", colors. red) -- Uranium Chest Status 1301

-- == REACTOR STATUS

if white == true then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,1)
  mon.write("Reactor 1:")
  mon.setCursorPos(18,1)
  mon.setTextColor(colors.lime)
  mon.setBackgroundColor(colors.black)
  mon.write("ONLINE ")
else
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,1)
  mon.write("Reactor 1:")
  mon.setCursorPos(18,1)
  mon.setTextColor(colors.red)
  mon.setBackgroundColor(colors.black)
  mon.write("OFFLINE")
end
-- == Coolant STATUS

if white == false then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,2)
  mon.write("Coolant Feed:")
  mon.setCursorPos(18,2)
  mon.setTextColor(colors.red)
  mon.setBackgroundColor(colors.black)
  mon.write("OFFLINE	")
else
if black == true then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,2)
  mon.write("Coolant Feed:")
  mon.setCursorPos(18,2)
  mon.setTextColor(colors.lime)
  mon.setBackgroundColor(colors.black)
  mon.write("ACTIVE ")
else
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,2)
  mon.write("Coolant Feed:")
  mon.setCursorPos(18,2)
  mon.setTextColor(colors.orange)
  mon.setBackgroundColor(colors.black)
  mon.write("IDLE   ")
end
-- == Uranium STATUS

if white == false then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,3)
  mon.write("Uranium Feed:")
  mon.setCursorPos(18,3)
  mon.setTextColor(colors.red)
  mon.setBackgroundColor(colors.black)
  mon.write("OFFLINE	")
else
if orange == true then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,3)
  mon.write("Uranium Feed:")
  mon.setCursorPos(18,3)
  mon.setTextColor(colors.lime)
  mon.setBackgroundColor(colors.black)
  mon.write("ACTIVE ")
else
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,3)
  mon.write("Uranium Feed:")
  mon.setCursorPos(18,3)
  mon.setTextColor(colors.orange)
  mon.setBackgroundColor(colors.black)
  mon.write("IDLE   ")
end

-- == Coolant Chest Status

if white == false then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,5)
  mon.write("Coolant Storage:")
  mon.setCursorPos(18,5)
  mon.setTextColor(colors.red)
  mon.setBackgroundColor(colors.black)
  mon.write("OFFLINE		 ")
else
if cchest == true then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,5)
  mon.write("Coolant Storage:")
  mon.setCursorPos(18,5)
  mon.setTextColor(colors.red)
  mon.setBackgroundColor(colors.black)
  mon.write("DEPLETED	   ")
else
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,5)
  mon.write("Coolant Storage:")
  mon.setCursorPos(18,5)
  mon.setTextColor(colors.orange)
  mon.setBackgroundColor(colors.black)
  mon.write("Feeding		 ")
end

-- == Uranium Chest Status

if white == false then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,6)
  mon.write("Uranium Storage:")
  mon.setCursorPos(18,6)
  mon.setTextColor(colors.red)
  mon.setBackgroundColor(colors.black)
  mon.write("OFFLINE		 ")
else
if uchest == true then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,6)
  mon.write("Uranium Storage:")
  mon.setCursorPos(18,6)
  mon.setTextColor(colors.red)
  mon.setBackgroundColor(colors.black)
  mon.write("DEPLETED	   ")
else
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,6)
  mon.write("Uranium Storage:")
  mon.setCursorPos(18,6)
  mon.setTextColor(colors.orange)
  mon.setBackgroundColor(colors.black)
  mon.write("Feeding		 ")
end

-- == MELTDOWN STATUS

if red == false then
  mon.setTextColor(colors.white)
  mon.setBackgroundColor(colors.black)
  mon.setCursorPos(1,12)
  mon.write("Reactor Temp:")
  mon.setCursorPos(18,12)
  mon.setTextColor(colors.lime)
  mon.setBackgroundColor(colors.black)
  mon.write("SAFE		  ")
else
shell.run("alarm")
end
os.sleep(1)
end
Edited on 21 April 2014 - 08:37 PM
CometWolf #2
Posted 21 April 2014 - 10:44 PM
redstone changes to the computer fires a redstone event, so replacing your sleep with os.pullEvent"redstone", would make it refresh whenever there's a change. I don't see any reboot command though… Also, only updating the text that has actually been changed would probably speed it up a lot.
Edited on 21 April 2014 - 08:46 PM
Xixili #3
Posted 21 April 2014 - 11:02 PM
Thank you.

Is it also possible that the reactor turns off when the coolant chest is empty?

I have this code so far that checks the insides of a chest with a Gate Reader.


while true do
sleep(0)
  m = peripheral.wrap("top")
  data = m.get()
  if data["Inventory Empty"] then
   rs.setOutput("bottom", true)
   sleep(4)
   rs.setOutput("bottom", false)
  end
end
Edited on 21 April 2014 - 10:45 PM
CometWolf #4
Posted 22 April 2014 - 05:29 AM
I don't see why not. Just set it up with a regular pull event with a timer to check the chest, and redstone to update the monitor.