Skew

Energy monitor RF

Apr 24th, 2020
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. -- Config
  2. width = 15
  3. height = 40
  4. interval = 3
  5. title = "Biomass"
  6. cell = peripheral.wrap("thermalexpansion:storage_cell_3")
  7. monitor = peripheral.wrap("monitor_2")
  8.  
  9.  
  10. monitor.setTextColor(colors.white)
  11. monitor.setTextScale(0.5)
  12.  
  13. -- Update screen
  14. function update()
  15.     print("Update")
  16.     -- Calculate energy
  17.     stored = cell.getEnergyStored()
  18.     total = cell.getEnergyCapacity()
  19.     p = math.floor((stored/total) * 10000.0) / 100.0
  20.     h = (stored/total) * height
  21.  
  22.     -- Draw box
  23.     prev = term.redirect(monitor)
  24.     paintutils.drawFilledBox(0, 0, width, height, colors.black)
  25.     paintutils.drawFilledBox(0, height-h, width, height, colors.blue)
  26.     term.redirect(prev)
  27.  
  28.     -- Draw text
  29.     monitor.setBackgroundColor(colors.black)
  30.     monitor.setCursorPos(1, 1)
  31.     monitor.write(title)
  32.     monitor.setCursorPos(1, 2)
  33.     monitor.write(p .. "%")
  34. end
  35.  
  36. -- Run endlessly
  37. print("Running")
  38. timer = os.startTimer(interval)
  39. while true do
  40.     event, param = os.pullEvent()
  41.     if event == "key" then
  42.         break
  43.     elseif event == "timer" and param == timer then
  44.         update()
  45.         timer = os.startTimer(interval)
  46.     end
  47. end
  48. print("Stopped")
Advertisement
Add Comment
Please, Sign In to add comment