Advertisement
Guest User

Power Monitoring Program ComputerCraft

a guest
Jun 23rd, 2014
1,632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 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. --Setup instructions for terminal
  8. term.setTextColour(colors.red)
  9. print("Running Setup")
  10. term.setTextColour(colors.lightblue)
  11. print("What is the name of your Monitor?")
  12. mon = io.read()
  13. print("What is the name of your Energy Storage Device?")
  14. cube = io.read()
  15. print("What is the Title for your Info Board?")
  16. title = io.read()
  17. print("What is the Energy Unit?")
  18. unit = io.read()
  19. term.setTextColour(colors.red)
  20. print("Confirm Settings")
  21. term.setTextColour(colors.orange)
  22. print("Monitor: "..mon)
  23. print("Battery: "..cube)
  24. print("Title: "..title)
  25. print("Unit: "..unit)
  26. term.setTextColour(colors.red)
  27. print("Hold CTRL+R to redo settings")
  28. sleep(1)
  29. print("Saving Settings")
  30. print("Settings Saved")
  31.  
  32. --Wraps the user input peripherals
  33. mon = peripheral.wrap(mon)
  34. cube = peripheral.wrap(cube)
  35.  
  36. mon.setTextColour(colors.purple)
  37. mon.setTextScale(1)
  38. mon.setCursorPos(0,0)
  39. mon.setBackgroundColour(colors.lightBlue)
  40. mon.print(title)
  41.  
  42. while true do
  43.    --calculates percentages and information regarding the energy storage
  44.    max = cube.getMaxEnergyStored()
  45.    cur = cube.getEnergyStored()
  46.    percentA = math.floor(cur/max)
  47.    percentA = math.floor(percent * 100)
  48.    percentB = math.floor(percentA + .05)
  49.    bar = 100/28
  50.  
  51.    mon.setCursorPos(0,1)
  52.    mon.setBackgroundColour(colors.white)
  53.    mon.setTextColour(colors.orange)
  54.    mon.clearLine()
  55.    mon.print("Current Energy: "..cur..unit)
  56.  
  57.    mon.setCursorPos(0,3)
  58.  
  59.    mon.setTextColour(colors.green)
  60.    mon.clearLine()
  61.    mon.print(percent.."% Full")
  62.    
  63.    --Percent Filling Bar
  64.    mon.setTextScale(.5)
  65.    mon.setCursorPos(0,4)
  66.    if 0==bar then
  67.       mon.setTextColour(colors.lightGray)
  68.       mon.setBackgroundColour(colors.lightGray)
  69.       mon.print("0000000000000000000000000000")
  70.    end
  71.    if bar<=percentA<=bar*2 or percentA==bar*2 then
  72.       mon.setCursorPos(0,4)
  73.  
  74.    end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement