Xonoa

reactorControlWireless

Jan 29th, 2021 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. -- https://www.lua.org/pil/20.3.html
  2. -- http://lua-users.org/wiki/PatternsTutorial
  3.  
  4.  
  5. local reactor = peripheral.find("BigReactors-Reactor")
  6. local modem = peripheral.wrap("top")
  7. local channel = 24816
  8. modem.open(channel)
  9. local drawer = peripheral.find("drawer")
  10.  
  11. --calculates run time based on fuel
  12. function calcRunTime(fuelLevel)
  13.     print("calc run time")
  14.     --(fuel level in mb / consumption rate in mb/t) / ticks per second
  15.     --  mb    t     s
  16.     -- ___ * ___ * ___ = s
  17.     --  1     mb    t
  18.     return ((fuelLevel / reactor.getFuelConsumedLastTick()) / 20)
  19. end
  20.  
  21. --calculates total fuel available in both reactor and storage
  22. function calcFuelLevel()
  23.     print("calc fuel level")
  24.     return ((drawer.getItemCount(1) * 1000) + reactor.getFuelAmount())
  25. end
  26.  
  27. --estimates total power producable with current fuel
  28. function calcTotalPower()
  29.     print("calc total power")
  30.     return (calcRunTime(calcFuelLevel()) * 20 * reactor.getEnergyProducedLastTick())
  31. end
  32.  
  33. --main loop. transmits fuel level and runtime estimate over wireless
  34. while true do
  35.     local fuelLevel = calcFuelLevel()
  36.     local runTime = calcRunTime(fuelLevel)
  37.     local totalPower = calcTotalPower()
  38.  
  39.     modem.transmit(channel, 3, fuelLevel)
  40.     os.sleep(1)
  41.    
  42.     modem.transmit(channel, 4, runTime)
  43.     os.sleep(1)
  44.    
  45.     modem.transmit(channel, 5, totalPower)
  46.     os.sleep(5)
  47. end
Add Comment
Please, Sign In to add comment