Files
nova-corp/temperature_driver.lua
2025-06-14 17:18:20 -04:00

44 lines
1.2 KiB
Lua

local max = 250
local min = 212
local function getValue()
local kelvin = reactor.getTemperature() or 0
local fahrenheit = (kelvin - 273.15) * 9 / 5 + 32
return math.floor(fahrenheit * 10000 + 0.5) / 10000
end
local function color()
local temperature = getValue()
return colors.black
end
local function watch()
while true do
print("Temperature: " .. getValue())
checkTemperature()
sleep(0.05) -- Update every tenth second
end
end
function checkTemperature()
local temperature = getValue()
local upperThreshold = max - 20
local lowerThreshold = min + 20
if temperature >= upperThreshold then
print("Warning: Temperature approaching upper limit! Taking action.")
burnRateDriver.stepDown()
elseif temperature <= lowerThreshold then
print("Warning: Temperature approaching lower limit! Taking action.")
burnRateDriver.stepUp()
end
end
local function report()
local value = getValue()
local color = color()
monitor.setBackgroundColor(color)
monitor.clearLine()
monitor.write("Temperature: " .. value .. "F")
end
return { report = report, watch = watch }