AsTio

Energy_Cube_Status_sender

Jun 21st, 2019
47
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cube = peripheral.wrap("Ultimate Energy Cube_0")
  2. modem = peripheral.wrap("top")
  3. modem.open(56000)
  4. -- ---------------------------------
  5. local function one()
  6.     while true do
  7.     energy = cube.getEnergy()
  8.     menergy = cube.getMaxEnergy()
  9.     term.clear()
  10.     term.setCursorPos(1,2)
  11.     term.clear()
  12.     print("Energy Cube: ")
  13.     print("Energy Stored: " ..energy)
  14.     print("Max Energy: " ..menergy)
  15.     percent = ( energy / menergy ) * 100
  16.     print("Charge percent: "..percent)
  17.  
  18.         timeout = os.startTimer(0.05)
  19.         event, s, f, rf, msg = os.pullEvent()
  20.         if event == "modem_message" then
  21.                 a = msg
  22.                 if msg == "ON" then
  23.                     wmodem.transmit(57000, 2, "ON")
  24.                  end
  25.                 if msg == "OFF" then
  26.                       wmodem.transmit(57000, 2, "OFF")
  27.                 end
  28.                 elseif event == "timer" then
  29.                      wmodem.transmit(57000, 2, tostring(a))
  30.         end
  31.         modem.transmit(58000, 1, {tostring(energy), tostring(menergy), tostring(percent)})
  32.     end
  33. end
  34.  
  35. -- ------------------------------
  36. while true do
  37. energy = cube.getEnergy()
  38.   menergy = cube.getMaxEnergy()
  39.   term.clear()
  40.   term.setCursorPos(1,2)
  41.   term.clear()
  42.   print("Energy Cube: ")
  43.   print("Energy Stored: " ..energy)
  44.   print("Max Energy: " ..menergy)
  45.   percent = ( energy / menergy ) * 100
  46.   print("Charge percent: "..percent)
  47.  
  48. timeout = os.startTimer(0.05)
  49. event, s, f, rf, msg = os.pullEvent()
  50. if event == "modem_message" then
  51.         a = msg
  52.         if msg == "ON" then
  53.             modem.transmit(57000, 2, "ON")
  54.         end
  55.         if msg == "OFF" then
  56.             modem.transmit(57000, 2, "OFF")
  57.         end
  58.     one()
  59.   elseif event == "timer" then
  60.         modem.transmit(57000, 2, "OFF")
  61.   end  
  62. modem.transmit(58000, 1, {tostring(energy), tostring(menergy), tostring(percent)})
  63. end
RAW Paste Data