Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 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.       end
  82.     elseif stored > 55 then
  83.       local run = true
  84.       local count = 0
  85.       while run do
  86.         if count == 0 then
  87.           local current = br.getControlRodLevel(1)
  88.           br.setAllControlRodLevels(current+1)
  89.           count = 31
  90.         end
  91.         sleep(1)
  92.         local new = br.getEnergyStored()/100000
  93.         if new < 50 then
  94.           run = false
  95.         end
  96.         count = count - 1
  97.       end
  98.     end
  99.     update_display()
  100.   elseif event == "monitor_touch" then
  101.     local level = br.getControlRodLevel(1)
  102.     if x >= 9 and x <= 13 then
  103.       if y == 10 then
  104.         br.setActive(not br.getActive())
  105.       elseif y == 13 then
  106.         br.setAllControlRodLevels(level+1)
  107.       elseif y == 15 then
  108.         br.setAllControlRodLevels(level+5)
  109.       elseif y == 17 then
  110.         br.setAllControlRodLevels(level+10)
  111.       end
  112.     elseif x >= 15 and x <= 19 then
  113.       if y == 13 then
  114.         br.setAllControlRodLevels(level-1)
  115.       elseif y == 15 then
  116.         br.setAllControlRodLevels(level-5)
  117.       elseif y == 17 then
  118.         br.setAllControlRodLevels(level-10)
  119.       end
  120.     end
  121.     update_display()
  122.   end  
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement