Advertisement
craftyoyo

compteur_elec_compt

Aug 18th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.57 KB | None | 0 0
  1.  
  2. p = {}
  3. rednet.open("right")
  4. local x = {peripheral.find("EnergyMeterRF")}
  5.  
  6. for k,v in  pairs(x) do
  7.     p[v.getLabel()] = v
  8. end
  9.  
  10. function loadDB()
  11.   local f = fs.open("db", "r")
  12.   db = textutils.unserialize(f.readAll())
  13.   f.close()
  14. end
  15.  
  16. function saveDB()
  17.   local f = fs.open("db", "w")
  18.   f.write(textutils.serialize(db))
  19.   f.close()
  20. end
  21.  
  22. while true do
  23.     e = {}
  24.     for k,v in pairs(p) do
  25.         if not v.isOutputAllowed() then
  26.             e[k] = -1
  27.             v.reset()
  28.         else       
  29.             e[k] = v.getCountAndReset()
  30.         end
  31.     end
  32.     rednet.send(171,textutils.serialize(e))
  33.     os.sleep(1)
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement