craftyoyo

compteur

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