rhn

DieselControl

rhn
May 1st, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. rsmax=14
  2. rsmin=4
  3.  
  4. local mon = peripheral.wrap("top")
  5.  
  6. local monScale = 0.5
  7. mon.setTextScale(monScale)
  8. mon.setBackgroundColor(colors.black)
  9. mon.clear()
  10. mon.setCursorPos(2,1)
  11. mon.write("Engine 1 (Left):")
  12. mon.setCursorPos(2,6)
  13. mon.write("Engine 2 (Right):")
  14.  
  15.  
  16. local w,h = mon.getSize()
  17.  
  18. w = math.floor(w / 2)
  19.  
  20. print(w," ",h)
  21.  
  22. local col3 = {colors.red, colors.yellow, colors.green}
  23. local col5 = {colors.red, colors.orange, colors.yellow, colors.lime, colors.green}
  24. local col, ncol, n
  25.  
  26. if w % 3 < w % 5 then
  27.   col = col3
  28.   ncol = 3
  29.   w = w - (w % 3)
  30. else
  31.   col = col5
  32.   ncol = 5
  33.   w = w - (w % 5)
  34. end
  35.  
  36. n = w / ncol
  37.  
  38. wNew1 = w
  39. wNew2 = w
  40. local start = true
  41.  
  42.  
  43.  
  44. lefton=false
  45. righton=false
  46. while true do
  47.     print(redstone.getAnalogInput("left").."/"..redstone.getAnalogInput("right"))
  48.  
  49.   wOld1 = wNew1
  50.   eNow1 = redstone.getAnalogInput("left")
  51.   eMax1 = 14
  52.   wNew1 = math.ceil(w * eNow1 / eMax1)
  53.  
  54.   if wOld1 ~= wNew1 or start then
  55.     mon.setBackgroundColor(colors.black)
  56.     for j = 2,5 do
  57.         for i=1,w*2 do
  58.             mon.setCursorPos(i,j)
  59.             mon.write(" ")
  60.         end
  61.     end
  62.  
  63.     for i = 1,wNew1 do
  64.       for j = 2,5 do
  65.         mon.setCursorPos(i*2 - 1,j)
  66.         mon.setBackgroundColor(col[math.ceil(i/n)])
  67.         mon.write(" ")
  68.         mon.setCursorPos(i*2,j)
  69.         mon.setBackgroundColor(colors.black)
  70.         mon.write(" ")
  71.       end
  72.     end
  73.   end
  74.  
  75.  
  76.   wOld2 = wNew2
  77.   eNow2 = redstone.getAnalogInput("right")
  78.   eMax2 = 14
  79.   wNew2 = math.ceil(w * eNow2 / eMax2)
  80.  
  81.   if wOld2 ~= wNew2 or start then
  82.     mon.setBackgroundColor(colors.black)
  83.     for j = 7,10 do
  84.         for i=1,w*2 do
  85.             mon.setCursorPos(i,j)
  86.             mon.write(" ")
  87.         end
  88.     end
  89.  
  90.     for i = 1,wNew2 do
  91.       for j = 7,10 do
  92.         mon.setCursorPos(i*2 - 1,j)
  93.         mon.setBackgroundColor(col[math.ceil(i/n)])
  94.         mon.write(" ")
  95.         mon.setCursorPos(i*2,j)
  96.         mon.setBackgroundColor(colors.black)
  97.         mon.write(" ")
  98.       end
  99.     end
  100.   end
  101. start = false
  102.  
  103.  
  104.     if redstone.getAnalogInput("right") >= rsmax then
  105.         if lefton then
  106.             redstone.setBundledOutput("bottom",3)
  107.         else
  108.             redstone.setBundledOutput("bottom",1)
  109.         end
  110.         righton=true
  111.     elseif redstone.getAnalogInput("right") <= rsmin then
  112.         if lefton then
  113.             redstone.setBundledOutput("bottom",2)
  114.         else
  115.             redstone.setBundledOutput("bottom",0)
  116.         end
  117.         righton=false
  118.     end
  119.  
  120.     if redstone.getAnalogInput("left") >= rsmax then
  121.         if righton then
  122.             redstone.setBundledOutput("bottom",3)
  123.         else
  124.             redstone.setBundledOutput("bottom",2)
  125.         end
  126.         lefton =true
  127.     elseif redstone.getAnalogInput("left") <= rsmin then
  128.         if righton then
  129.             redstone.setBundledOutput("bottom",1)
  130.         else
  131.             redstone.setBundledOutput("bottom",0)
  132.         end
  133.         lefton=false
  134.     end
  135. sleep(5)
  136. end
Add Comment
Please, Sign In to add comment