Advertisement
Guest User

startup.lua

a guest
Sep 3rd, 2021
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. threshold = 0.6
  2. mon = peripheral.wrap("monitor_1")
  3.  
  4. cells = {
  5.     peripheral.wrap("thermal:energy_cell_1"),
  6.     peripheral.wrap("thermal:energy_cell_2"),
  7.     peripheral.wrap("thermal:energy_cell_3"),
  8.     peripheral.wrap("thermal:energy_cell_4")
  9. }
  10.  
  11. function writeMonStatus (state,fraction)
  12.   local pct = math.floor(fraction*10000)/100
  13.   mon.clear()
  14.   if mon.setTextScale ~= nil then
  15.     mon.setTextScale(1)
  16.     local width, height = mon.getSize()
  17.     if width < 15 or height < 5 then -- Small monitor - scale down
  18.       mon.setTextScale(0.5)
  19.     else -- Large monitor - scale up
  20.       local scale = math.min(width / 14, height / 2, 5)
  21.       scale = math.floor(scale * 2) / 2 -- multiple of 0.5
  22.       mon.setTextScale(scale)
  23.     end
  24.   end
  25.   mon.setCursorPos(1,1)
  26.   mon.write("State: " .. (state and "On" or "Off"))
  27.   mon.setCursorPos(1,2)
  28.   mon.write("Energy: " .. pct .. "%")
  29. end
  30.  
  31. while true do
  32.   local energyCur = 0
  33.   local energyMax = 0
  34.  
  35.   for _,cell in pairs(cells) do
  36.     energyCur = energyCur + cell.getEnergy()
  37.     energyMax = energyMax + cell.getEnergyCapacity()
  38.   end
  39.  
  40.   local energyFraction = energyCur/energyMax
  41.   print(energyFraction)
  42.  
  43.   local state = energyFraction < threshold
  44.   redstone.setOutput("left",state)
  45.   writeMonStatus(state,energyFraction)
  46.  
  47.   sleep(10)
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement