Saereth

EnergyMonitor

Jan 31st, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   term.setTextColour(colors.lime)
  2.   term.setTextColour(colors.lightBlue)
  3.   term.setTextColour(colors.red)
  4.   term.setTextColour(colors.yellow)
  5.   mon = "monitor_2"
  6.   term.setTextColour(colors.red)
  7.   term.setTextColour(colors.yellow)
  8.   cube = "RFStorageBattery_1"
  9.   term.setTextColour(colors.red)
  10.   term.setTextColour(colors.yellow)
  11.   title = "Energy Vortex"
  12.   term.setTextColour(colors.red)
  13.   term.setTextColour(colors.blue)
  14.   term.setTextColour(colors.red)
  15.  
  16. --Center Text Function
  17.   function centerText(text,yVal)
  18.     length = string.len(text)
  19.     minus = math.floor(54-length)
  20.     x = math.floor(minus/2)
  21.     mon.setCursorPos(x+1,yVal)
  22.     mon.write(text)
  23.   end
  24.  
  25. --Wraps the Peripherals
  26.   cube = peripheral.wrap(cube)
  27.   mon = peripheral.wrap(mon)
  28.  
  29. --Sets the BackGround to White    (Messy!  I know!)
  30.   function clearScreen()
  31.     mon.clear()
  32.     mon.setBackgroundColour(colors.white)
  33.     mon.setCursorPos(1,1)
  34.     mon.write(string.rep(" ",54))
  35.     mon.setCursorPos(1,2)
  36.     mon.write(string.rep(" ",54))
  37.     mon.setCursorPos(1,3)
  38.     mon.write(string.rep(" ",54))
  39.     mon.setCursorPos(1,4)
  40.     mon.write(string.rep(" ",54))
  41.     mon.setCursorPos(1,5)
  42.     mon.write(string.rep(" ",54))
  43.     mon.setCursorPos(1,6)
  44.     mon.write(string.rep(" ",54))
  45.     mon.setCursorPos(1,7)
  46.     mon.write(string.rep(" ",54))
  47.     mon.setCursorPos(1,8)
  48.     mon.write(string.rep(" ",54))
  49.     mon.setCursorPos(1,9)
  50.     mon.write(string.rep(" ",54))
  51.     mon.setCursorPos(1,10)
  52.     mon.write(string.rep(" ",54))
  53.   end
  54.  
  55.   clearScreen()
  56. --Centers and Displays Title On Monitor
  57.   mon.setBackgroundColour(colors.lightGray)
  58.   mon.setTextColour(colors.red)
  59.   mon.setTextScale(0.85)
  60.   mon.setCursorPos(1,1)
  61.   centerText(string.rep(" ",string.len(title)+2),1)
  62.   centerText(title,1)
  63.  
  64. while true do
  65.     --Variables for Calculations
  66.     maxE = 1200000000000
  67.     curE = cube.getEnergyStored("top")
  68.     rawPer = curE/maxE
  69.     rawPer = rawPer/1000000
  70.     percent = math.floor((rawPer*100)+0.5)
  71.     bar = math.floor((rawPer*52)+0.5)
  72.    
  73.     mon.setBackgroundColour(colors.white)
  74.     mon.setTextColour(colors.blue)
  75.     centerText("Current Energy: "..curE.." MrR",3)
  76.     mon.setTextColour(colors.green)
  77.     centerText(percent.."% Full",6)
  78.    
  79.     --Loading Bar Code Re-Written Much MUCH simpler than before
  80.     mon.setCursorPos(2,8)
  81.     mon.setBackgroundColour(colors.gray)
  82.     mon.write(string.rep(" ",52))
  83.     mon.setCursorPos(2,8)
  84.     mon.setBackgroundColour(colors.lime)
  85.     mon.write(string.rep(" ",bar))
  86.    
  87.     mon.setCursorPos(2,9)
  88.     mon.setBackgroundColour(colors.gray)
  89.     mon.write(string.rep(" ",52))
  90.     mon.setCursorPos(2,9)
  91.     mon.setBackgroundColour(colors.lime)
  92.     mon.write(string.rep(" ",bar))
  93. end
Advertisement
Add Comment
Please, Sign In to add comment