MoJoCreatior

Power Monitor V:2 _OLD

Feb 13th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. --[[  Power Monitoring Program Written By: 0_Mr_Redstone_0  AKA  MoJoCreatior
  2. This code is considered free for use both commercial and private and can be redistributed so long as it meats following criteria:
  3. 1: 0_Mr_Redstone_0 and MoJoCreatior are credited as the original authors
  4. 2: You do not try to take full ownership of the code/written program
  5. 3: If you modify the code for re-upload you must provide it under the same conditions. as in- Open Source, and credited to me as original author]]
  6.  
  7. --Power Monitoring Program
  8. --Version 2
  9.  
  10. --Setup
  11.   term.setTextColour(colors.lime)
  12.   print("Power Monitor Setup")
  13.   term.setTextColour(colors.lightBlue)
  14.   print("Launching Configuration...")
  15.   term.setTextColour(colors.red)
  16.   print("What is the name of your Monitor?")
  17.   term.setTextColour(colors.yellow)
  18.   mon = io.read()
  19.   term.setTextColour(colors.red)
  20.   print("What is the name of your Energy Storage Device?")
  21.   term.setTextColour(colors.yellow)
  22.   cube = io.read()
  23.   term.setTextColour(colors.red)
  24.   print("What is the Power Monitor going to be Titled? 36 Characters Max!")
  25.   term.setTextColour(colors.yellow)
  26.   title = io.read()
  27.   term.setTextColour(colors.red)
  28.   print("Confirm Settings")
  29.   term.setTextColour(colors.blue)
  30.   print("Monitor: "..mon)
  31.   print("Battery: "..cube)
  32.   print("Title: "..title)
  33.   term.setTextColour(colors.red)
  34.   print("Hold CTRL+R to redo settings.")
  35.   sleep(2)
  36.   print("Settings Saved!")
  37.  
  38. --Center Text Function
  39.   function centerText(text,yVal)
  40.     length = string.len(text)
  41.     minus = math.floor(36-length)
  42.     x = math.floor(minus/2)
  43.     mon.setCursorPos(x+1,yVal)
  44.     mon.write(text)
  45.   end
  46.  
  47. --Wraps the Peripherals
  48.   cube = peripheral.wrap(cube)
  49.   mon = peripheral.wrap(mon)
  50.  
  51. --Sets the BackGround to White    (Messy!  I know!)
  52.   function clearScreen()
  53.     mon.clear()
  54.     mon.setBackgroundColour(colors.white)
  55.     mon.setCursorPos(1,1)
  56.     mon.write(string.rep(" ",36))
  57.     mon.setCursorPos(1,2)
  58.     mon.write(string.rep(" ",36))
  59.     mon.setCursorPos(1,3)
  60.     mon.write(string.rep(" ",36))
  61.     mon.setCursorPos(1,4)
  62.     mon.write(string.rep(" ",36))
  63.     mon.setCursorPos(1,5)
  64.     mon.write(string.rep(" ",36))
  65.     mon.setCursorPos(1,6)
  66.     mon.write(string.rep(" ",36))
  67.     mon.setCursorPos(1,7)
  68.     mon.write(string.rep(" ",36))
  69.     mon.setCursorPos(1,8)
  70.     mon.write(string.rep(" ",36))
  71.     mon.setCursorPos(1,9)
  72.     mon.write(string.rep(" ",36))
  73.     mon.setCursorPos(1,10)
  74.     mon.write(string.rep(" ",36))
  75.   end
  76.  
  77.   clearScreen()
  78. --Centers and Displays Title On Monitor
  79.   mon.setBackgroundColour(colors.lightGray)
  80.   mon.setTextColour(colors.red)
  81.   mon.setTextScale(0.5)
  82.   mon.setCursorPos(1,1)
  83.   centerText(string.rep(" ",string.len(title)+2),1)
  84.   centerText(title,1)
  85.  
  86. while true do
  87.     --Variables for Calculations
  88.     maxE = cube.getMaxEnergyStored("top")
  89.     curE = cube.getEnergyStored("top")
  90.     rawPer = curE/maxE
  91.     percent = math.floor((rawPer*100)+0.5)
  92.     bar = math.floor((rawPer*34)+0.5)
  93.    
  94.     mon.setBackgroundColour(colors.white)
  95.     mon.setTextColour(colors.blue)
  96.     centerText("Current Energy: "..curE.." RF",3)
  97.     mon.setTextColour(colors.green)
  98.     centerText(percent.."% Full",6)
  99.    
  100.     --Loading Bar Code Re-Written Much MUCH simpler than before
  101.     mon.setCursorPos(2,8)
  102.     mon.setBackgroundColour(colors.gray)
  103.     mon.write(string.rep(" ",34))
  104.     mon.setCursorPos(2,8)
  105.     mon.setBackgroundColour(colors.lime)
  106.     mon.write(string.rep(" ",bar))
  107.    
  108.     mon.setCursorPos(2,9)
  109.     mon.setBackgroundColour(colors.gray)
  110.     mon.write(string.rep(" ",34))
  111.     mon.setCursorPos(2,9)
  112.     mon.setBackgroundColour(colors.lime)
  113.     mon.write(string.rep(" ",bar))
  114. end
Add Comment
Please, Sign In to add comment