Advertisement
Sparkybearbomb

Induction Battery Wireless Pad Monitor

Oct 8th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.26 KB | None | 0 0
  1. sleep(1)
  2. print("waiting for connection...")
  3.  
  4.  
  5.  
  6. local modem = peripheral.wrap("back")
  7. local maxVal = 0
  8. local minVal = 0
  9. local input = 0
  10. local output = 0
  11. local delta = 0
  12. local capper = 0
  13.  
  14. function clear()
  15.   term.setBackgroundColor(colors.black)
  16.   term.clear()
  17.   term.setCursorPos(1,1)
  18. end
  19.  
  20. -- Round Decimal Numbers
  21. function roundNumber(num, n)
  22.   local mult = 10^(n or 0)
  23.   return math.floor(num * mult + 0.5) / mult
  24. end
  25.  
  26. while true do
  27. modem.closeAll()
  28. modem.open(1)
  29. event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  30. maxVal = message
  31. modem.closeAll()
  32. modem.open(2)
  33. event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  34. minVal = message
  35. modem.closeAll()
  36. modem.open(3)
  37. event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  38. input = message
  39. modem.closeAll()
  40. modem.open(4)
  41. event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  42. output = message
  43. modem.closeAll()
  44. modem.open(5)
  45. event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  46. delta = message
  47. modem.closeAll()
  48. modem.open(6)
  49. event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  50. capper = message
  51. modem.closeAll()
  52.  
  53.   term.clear()
  54.   term.setCursorPos(2,1)
  55.   term.setTextColor(colors.yellow)
  56.   term.write("Capacity:")
  57.   term.setCursorPos(2,3)
  58.   term.write("Input: ")
  59.   term.setCursorPos(2,5)
  60.   term.write("Output: ")
  61.   term.setCursorPos(2,7)
  62.   term.write("Delta: ")
  63.  
  64. --line 1/2
  65.   term.setCursorPos(2,2)
  66.   if maxVal < 1000 then
  67.     term.write(roundNumber(((math.floor(minVal))/1), 2).."/"..(roundNumber((maxVal/1), 2)).." RF")
  68.   else if maxVal < 1000000 then
  69.     term.write(roundNumber(((math.floor(minVal))/1000), 2).."/"..(roundNumber((maxVal/1000), 2)).." KRF")
  70.   else if maxVal < 1000000000 then
  71.     term.write(roundNumber(((math.floor(minVal))/1000000), 2).."/"..(roundNumber((maxVal/1000000), 2)).." MRF")
  72.   else if maxVal < 1000000000000 then
  73.     term.write(roundNumber(((math.floor(minVal))/1000000000), 2).."/"..(roundNumber((maxVal/1000000000), 2)).." GRF")
  74.   else if maxVal < 1000000000000000 then
  75.     term.write(roundNumber(((math.floor(minVal))/1000000000000), 2).."/"..(roundNumber((maxVal/1000000000000), 2)).." TRF")
  76.   else
  77.     term.write(roundNumber(((math.floor(minVal))/1000000000000000), 2).."/"..(roundNumber((maxVal/1000000000000000), 2)).." PRF")
  78.   end
  79.   end
  80.   end
  81.   end
  82.   end
  83.  
  84. --Line 3/4
  85.   term.setCursorPos(2,4)
  86.   if input < 1000 then
  87.     term.write(roundNumber(((math.floor(input))/1), 2).." RF/T")
  88.   else if input < 1000000 then
  89.     term.write(roundNumber(((math.floor(input))/1000), 2).." KRF/T")
  90.   else if input < 1000000000 then
  91.     term.write(roundNumber(((math.floor(input))/1000000), 2).." MRF/T")
  92.   else if input < 1000000000000 then
  93.     term.write(roundNumber(((math.floor(input))/1000000000), 2).." GRF/T")
  94.   else if input < 1000000000000000 then
  95.     term.write(roundNumber(((math.floor(input))/1000000000000), 2).." TRF/T")
  96.   else
  97.     term.write(roundNumber(((math.floor(input))/1000000000000000), 2).." PRF/T")
  98.   end
  99.   end
  100.   end
  101.   end
  102.   end
  103.  
  104.  
  105. --Line 5/6
  106.   term.setCursorPos(2,6)
  107.   if output < 1000 then
  108.     term.write(roundNumber(((math.floor(output))/1), 2).." RF/T")
  109.   else if output < 1000000 then
  110.     term.write(roundNumber(((math.floor(output))/1000), 2).." KRF/T")
  111.   else if output < 1000000000 then
  112.     term.write(roundNumber(((math.floor(output))/1000000), 2).." MRF/T")
  113.   else if output < 1000000000000 then
  114.     term.write(roundNumber(((math.floor(output))/1000000000), 2).." GRF/T")
  115.   else if output < 1000000000000000 then
  116.     term.write(roundNumber(((math.floor(output))/1000000000000), 2).." TRF/T")
  117.   else
  118.     term.write(roundNumber(((math.floor(output))/1000000000000000), 2).." PRF/T")
  119.   end
  120.   end
  121.   end
  122.   end
  123.   end
  124.  
  125.  
  126.  
  127. --Line 7/8
  128.   if delta > 0 then
  129.     term.setTextColor(colors.lime)
  130.   else
  131.     term.setTextColor(colors.red)
  132.   end
  133.   term.setCursorPos(2,8)
  134.  
  135.   if delta < -1000000000000000 then
  136.     term.write(roundNumber(((math.floor(delta))/1000000000000000), 2).." PRF/T")
  137.   else if delta < -1000000000000 then
  138.     term.write(roundNumber(((math.floor(delta))/1000000000000), 2).." TRF/T")
  139.   else if delta < -1000000000 then
  140.     term.write(roundNumber(((math.floor(delta))/1000000000), 2).." GRF/T")
  141.   else if delta < -1000000 then
  142.     term.write(roundNumber(((math.floor(delta))/1000000), 2).." MRF/T")
  143.   else if delta < -1000 then
  144.     term.write(roundNumber(((math.floor(delta))/1000), 2).." KRF/T")
  145.   else if delta < 1000 then
  146.     term.write(roundNumber(((math.floor(delta))/1), 2).." RF/T")
  147.   else if delta < 1000000 then
  148.     term.write(roundNumber(((math.floor(delta))/1000), 2).." KRF/T")
  149.   else if delta < 1000000000 then
  150.     term.write(roundNumber(((math.floor(delta))/1000000), 2).." MRF/T")
  151.   else if delta < 1000000000000 then
  152.     term.write(roundNumber(((math.floor(delta))/1000000000), 2).." GRF/T")
  153.   else if delta < 1000000000000000 then
  154.     term.write(roundNumber(((math.floor(delta))/1000000000000), 2).." TRF/T")
  155.   else
  156.     term.write(roundNumber(((math.floor(delta))/1000000000000000), 2).." PRF/T")
  157.   end
  158.   end
  159.   end
  160.   end
  161.   end
  162.   end
  163.   end
  164.   end
  165.   end
  166.   end
  167.  
  168.   sleep(0.1)
  169.  
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement