Advertisement
Guest User

oil_control

a guest
May 29th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. local zonePercent = 20
  2. local redPos = 'bottom'
  3. local bankPos = 'right'
  4. local monPos = 'top'
  5.  
  6. local bank = peripheral.wrap(bankPos)
  7. local mon = peripheral.wrap(monPos)
  8. local state = false
  9.  
  10. function changeStateIfNeeded()
  11.   local energy = bank.getEnergyStored()
  12.   local maxEnergy = bank.getMaxEnergyStored()
  13.   local topLimit = maxEnergy - 5000
  14.   local botLimit = topLimit * (
  15.     1 - (zonePercent/100)
  16.   )
  17.  
  18.   if energy < botLimit then
  19.     state = true
  20.   elseif energy > topLimit then
  21.     state = false
  22.   end
  23.  
  24.   redstone.setOutput(redPos, state)
  25. end
  26.  
  27. function showInfo()
  28.   term.setCursorPos(1,1)
  29.   mon.setCursorPos(1,1)
  30. --  term.clearLine()
  31.   local energy = bank.getEnergyStored()
  32.   local s = "Energy: "..energy.."         "
  33.   term.write(s)
  34.   mon.write(s)
  35.    
  36.   term.setCursorPos(1,2)
  37.   mon.setCursorPos(1,2)
  38. --  term.clearLine()
  39.   local status = "charging"
  40.   if not state then
  41.     status = "dis"..status
  42.   end
  43.   s = "Status: "..status
  44.  
  45.   term.write(s)
  46.   mon.write(s)
  47.  
  48.   term.setCursorPos(1,3)
  49.   mon.setCursorPos(1,3)
  50. end
  51.  
  52. --for t = 0, 100 do
  53. while true do
  54.   changeStateIfNeeded()
  55.   showInfo()
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement