Advertisement
Guest User

powerMon2.lua

a guest
Dec 14th, 2019
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. batSide = "left"
  2. genSide = "back"
  3. setLevel = 1      --what % energy to turn genny on.
  4. resetLevel = 95   --what % energy to turn genny off.
  5.  
  6. running = false
  7. mon = peripheral.wrap("monitor_0")
  8. bat = peripheral.wrap(batSide)
  9. maxEnergy = bat.getMaxEnergy()
  10. rs.setOutput(genSide, running)
  11. mon.setBackgroundColor(colors.black)
  12. mon.clear()
  13. blinkState = false
  14.  
  15. function doScreen(level)
  16.   if running then blinkColor = colors.green else blinkColor = colors.red end
  17.   mon.setTextColor(blinkColor)
  18.   local lvl = (math.floor((level * 10) + 0.5))/10
  19.   mon.setCursorPos(1,3)
  20.   mon.write("     ")
  21.   if lvl < 10 then mon.setCursorPos(3,3) else mon.setCursorPos(2,3) end
  22.   mon.write(string.format("%.1f", lvl).."%")
  23.  
  24.   mon.setCursorPos(7,1)
  25.   if blinkState then mon.setBackgroundColor(colors.black) else mon.setBackgroundColor(blinkColor) end
  26.   mon.write(" ")
  27.   if blinkState then
  28.     blinkState = false
  29.   else
  30.     blinkState = true
  31.     mon.setBackgroundColor(colors.black)
  32.   end
  33. end
  34.  
  35. while true do
  36.   energy = bat.getEnergy()
  37.   level = (energy / maxEnergy) * 100
  38.   if running then
  39.     if level >= resetLevel then
  40.       running = false
  41.       rs.setOutput(genSide, running)
  42.     end
  43.   else
  44.     if level <= setLevel then
  45.       running = true
  46.       rs.setOutput(genSide, running)
  47.     end
  48.   end
  49.  
  50.   doScreen(level)
  51.  
  52.   local lvl = (math.floor((level * 1000) + 0.5))/1000
  53.  
  54.   print("Energy: "..energy.. "/"..maxEnergy.." Level:"..string.format("%.3f", lvl).."% Running:"..tostring(running))
  55.   sleep(1)
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement