View difference between Paste ID: 387SE9Wi and RwtKTBXg
SHOW: | | - or go back to the newest paste.
1
--
2
-- Remote monitor component for reactor control program
3
--
4
-- Author: VirtualDXS
5
--
6
-- History:
7
--     v0.1, 2021-09-03
8
--         First version
9
10
threshold = 0.6
11
mon = peripheral.wrap("monitor_1")
12
13
cells = {
14
    peripheral.wrap("thermal:energy_cell_1"),
15
    peripheral.wrap("thermal:energy_cell_2"),
16
    peripheral.wrap("thermal:energy_cell_3"),
17
    peripheral.wrap("thermal:energy_cell_4")
18
}
19
20
function writeMonStatus (state,fraction)
21
  local pct = math.floor(fraction*10000)/100
22
  mon.clear()
23
  if mon.setTextScale ~= nil then
24
    mon.setTextScale(1)
25
    local width, height = mon.getSize()
26
    if width < 15 or height < 5 then -- Small monitor - scale down
27
      mon.setTextScale(0.5)
28
    else -- Large monitor - scale up
29
      local scale = math.min(width / 14, height / 2, 5)
30
      scale = math.floor(scale * 2) / 2 -- multiple of 0.5
31
      mon.setTextScale(scale)
32
    end
33
  end
34
  mon.setCursorPos(1,1)
35
  mon.write("State: " .. (state and "On" or "Off"))
36
  mon.setCursorPos(1,2)
37
  mon.write("Energy: " .. pct .. "%")
38
end
39
40
while true do
41
  local energyCur = 0
42
  local energyMax = 0
43
  
44
  for _,cell in pairs(cells) do
45
    energyCur = energyCur + cell.getEnergy()
46
    energyMax = energyMax + cell.getEnergyCapacity()
47
  end
48
49
  local energyFraction = energyCur/energyMax
50
  print(energyFraction)
51
  
52
  local state = energyFraction < threshold
53
  redstone.setOutput("left",state)
54
  writeMonStatus(state,energyFraction)
55
  
56
  sleep(10)
57
end