Advertisement
Guest User

br control

a guest
Aug 22nd, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. local br = peripheral.wrap("back")
  2. local m = peripheral.wrap("bottom")
  3.  
  4. br.setActive(true)
  5.  
  6. function power()
  7.   m.setCursorPos(2,10)
  8.   m.write("Power: ")
  9.   m.setCursorPos(9,10)
  10.   local active = " ON  "
  11.   if br.getActive() then
  12.     m.setBackgroundColor(colors.green)
  13.   else
  14.     active = " OFF "
  15.     m.setBackgroundColor(colors.red)
  16.   end
  17.   m.write(active)
  18.   m.setBackgroundColor(colors.black)
  19. end
  20.  
  21. function control()
  22.   m.setCursorPos(2,13)
  23.   m.write("Rods: ")
  24.   m.setCursorPos(9,13)
  25.   m.setBackgroundColor(colors.green)
  26.   m.write(" +1% ")
  27.   m.setCursorPos(9,15)
  28.   m.write(" +5% ")
  29.   m.setCursorPos(9,17)
  30.   m.write(" +10%")
  31.   m.setBackgroundColor(colors.red)
  32.   m.setCursorPos(15,13)
  33.   m.write(" -1% ")
  34.   m.setCursorPos(15,15)
  35.   m.write(" -5% ")
  36.   m.setCursorPos(15,17)
  37.   m.write(" -10%")
  38.   m.setBackgroundColor(colors.black)
  39. end
  40.  
  41. function update_display()
  42.   m.setTextColor(colors.white)
  43.   m.setBackgroundColor(colors.black)
  44.   m.clear()
  45.   m.setCursorPos(2,2)
  46.  
  47.   rf = br.getEnergyProducedLastTick()/1000
  48.   mb = br.getFuelConsumedLastTick()
  49.  
  50.   m.write(rf.." KiRF/t")
  51.   m.setCursorPos(2,4)
  52.   m.write(mb.." mB/t")
  53.   m.setCursorPos(2,6)
  54.   m.write("Control Rods: "..br.getControlRodLevel(1).."%")
  55.  
  56.   power()
  57.   control()
  58. end
  59.  
  60. while true do
  61.   os.startTimer(1)
  62.   local event,s,x,y = os.pullEvent()
  63.   if event == "timer" then
  64.     local stored = br.getEnergyStored()/100000
  65.     print(stored)
  66.     if stored < 45 then
  67.       local run = true
  68.       local count = 0
  69.       while run do
  70.         if count == 0 then
  71.           local current = br.getControlRodLevel(1)
  72.           br.setAllControlRodLevels(current-1)
  73.           count = 6
  74.         end
  75.         sleep(1)
  76.         local new = br.getEnergyStored()/100000
  77.         if new > 50 then
  78.           run = false
  79.         end
  80.         count = count - 1
  81.     update_display()
  82.       end
  83.     elseif stored > 55 then
  84.       local run = true
  85.       local count = 0
  86.       while run do
  87.         if count == 0 then
  88.           local current = br.getControlRodLevel(1)
  89.           br.setAllControlRodLevels(current+1)
  90.           count = 31
  91.         end
  92.         sleep(1)
  93.         local new = br.getEnergyStored()/100000
  94.         if new < 50 then
  95.           run = false
  96.         end
  97.         count = count - 1
  98.     update_display()
  99.       end
  100.     end
  101.     update_display()
  102.   elseif event == "monitor_touch" then
  103.     local level = br.getControlRodLevel(1)
  104.     if x >= 9 and x <= 13 then
  105.       if y == 10 then
  106.         br.setActive(not br.getActive())
  107.       elseif y == 13 then
  108.         br.setAllControlRodLevels(level+1)
  109.       elseif y == 15 then
  110.         br.setAllControlRodLevels(level+5)
  111.       elseif y == 17 then
  112.         br.setAllControlRodLevels(level+10)
  113.       end
  114.     elseif x >= 15 and x <= 19 then
  115.       if y == 13 then
  116.         br.setAllControlRodLevels(level-1)
  117.       elseif y == 15 then
  118.         br.setAllControlRodLevels(level-5)
  119.       elseif y == 17 then
  120.         br.setAllControlRodLevels(level-10)
  121.       end
  122.     end
  123.     update_display()
  124.   end  
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement