rcook

Redstone Energy Cell Reader

Mar 9th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- use an "Energy Sensor Kit" to right click on a Redstone Energy Cell
  2. -- put the card in a "Nuclear Information Reader"
  3. -- use this program in a computer to read the energy level
  4.  
  5. -- the Nuclear Information Reader is on the left
  6. m = peripheral.wrap("left")
  7.  
  8. local sleepTime = 20
  9. local stopEnginePercent = 95
  10. local startEnginePercent = 10
  11.  
  12. while (true) do
  13.   local current = 0
  14.   local capacity = 0
  15.   local percent = 0
  16.   a,b,c,info = m.get(1)
  17.  
  18.   -- find the current energy level and max capacity
  19.   for system, status in pairs(info) do
  20.     if system == "energyL" then
  21.       current = status
  22.     else
  23.       if system == "maxStorageL" then
  24.         capacity = status
  25.       end
  26.     end
  27.   end
  28.  
  29.   if capacity > 0 then
  30.     percent = 100 * current / capacity
  31.     print(tostring(current) .. " / " .. tostring(capacity) .. " (" .. tostring(percent) .. " %)")
  32.   else
  33.     print "Failed to read energy level"
  34.   end
  35.  
  36.   if percent < startEnginePercent then
  37.     -- turn on the engines
  38.     print("Engines are on")
  39.     redstone.setOutput("right", false)
  40.   else
  41.     if percent > stopEnginePercent then
  42.       -- turn off the engines
  43.       print("Engines are off")
  44.       redstone.setOutput("right", true)
  45.     else
  46.       -- not changing the current state of the engines
  47.       print("Engines continuing in current state")
  48.     end
  49.   end
  50.  
  51.   sleep(sleepTime)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment