Advertisement
hyndgrinder

ECCM

Nov 12th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. -----Energy Cell Consumption Monitor--
  2. function cellVerify()
  3. while turtle.detect()==false do
  4. print("No cell detected")
  5. sleep(0.2)
  6. end
  7. print("Cell detected, resuming...")
  8. end
  9.  
  10. function cellReplace()
  11. if turtle.dig()==true then print "Cell removed." end
  12. if turtle.dropUp()==true then print "Empty cell returned." end
  13. if turtle.suckDown()==true then print "New Cell Found." end
  14. if turtle.place()==true then print "Cell replaced." end
  15. cellVerify()
  16. end
  17.  
  18. cell=peripheral.wrap("front")
  19. print (cell)
  20. modem=peripheral.wrap("right")
  21. if modem==true then
  22. rednet.open("right")
  23. end
  24. id=os.getComputerID()
  25. name=os.getComputerLabel()
  26.  
  27. while true do
  28. cell=peripheral.wrap("front")
  29. if cell then
  30. print (cell)
  31. else
  32. print ("NO cell found")
  33. cellReplace()
  34. sleep(2)
  35.  
  36. end
  37.  
  38. ESlast=0
  39. while cell do
  40. term.clear()
  41. term.setCursorPos(1,1)
  42. print("----Energy Cell Consumption Monitor----")
  43. ES=tonumber(cell.getEnergyStored())
  44. print("Energy Stored:  ".. ES)
  45. if ES<10 then
  46. print("Cell Empty, replacing...")
  47. cellReplace()
  48. end
  49.  
  50. if ES>0 then
  51.     used=ESlast-ES
  52.     conS=tonumber(used/5)
  53.     conT=tonumber(used/5)
  54.     lclTbl= {cID=id, cName=name, pct=math.floor(ES/600000*100), cRate=conT}
  55.     if modem==true then
  56.     rednet.send(82, textutils.serialize(lclTbl))
  57.     end    
  58. --          ES, used, conT, conS}
  59.     if used<0 then
  60.     print("please wait while I get my first reading..." )
  61.     else
  62.     print("Computer: ".. id..", ".. name)
  63.     for k,v in pairs(lclTbl) do
  64.     print (k..".."..v)
  65.     --print("Consumption:  ".. conS .. "MJ/second (".. conT .. " MJ/tick)")
  66.     end
  67.     end
  68.     ESlast=ES
  69. end
  70.  
  71.  
  72. used=0
  73. sleep(5)
  74. end
  75. sleep(0.5)
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement