Advertisement
Guest User

rstest

a guest
Jul 20th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.69 KB | None | 0 0
  1. local component = require("component")
  2. local pc = require("computer")
  3. local sides = require("sides")
  4. local rs = component.redstone
  5. maxEnergy = pc.maxEnergy()
  6. chargeTo = 95
  7.  
  8. function rson()
  9.   rs.setOutput(sides.left,15)
  10. end
  11. function rsoff()
  12.   rs.setOutput(sides.left,0)
  13. end
  14.  
  15. function round(num,numDecimalPlaces)
  16.   local mult = 10^(numDecimalPlaces or 0)
  17.   return math.floor(num * mult + 0.5) /mult
  18. end
  19.  
  20. function updateEnergy()
  21.   currentEnergy = pc.energy()
  22.   chargeState = round(((currentEnergy / maxEnergy) * 100),2)
  23. end
  24.  
  25. updateEnergy()
  26. print(chargeState)
  27. if chargeState <= chargeTo then
  28.   rson()
  29.   while chargeState <= chargeTo do
  30.     os.sleep(1)
  31.     updateEnergy()
  32.     print(chargeState)
  33.   end
  34.   rsoff()
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement