dynamicXblue

Pressure Controller CC

Oct 27th, 2021 (edited)
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. local monitor = nil
  2. local compressor = nil
  3. local diskSide = nil
  4.  
  5. local outSide = nil
  6.  
  7. while monitor == nil or compressor == nil or diskSide == nil do
  8.    
  9.     for _, side in ipairs(rs.getSides()) do
  10.        
  11.         if peripheral.isPresent(side) then
  12.            
  13.             if peripheral.getType(side) == "monitor" then
  14.                 monitor = peripheral.wrap(side)
  15.  
  16.             elseif peripheral.getType(side) == "drive" then
  17.                 diskSide = side
  18.  
  19.             elseif string.gmatch(peripheral.getType(side), "compressor") then
  20.                 compressor = peripheral.wrap(tostring(side))
  21.                 outSide = side
  22.             end
  23.        
  24.         end
  25.    
  26.     end
  27.  
  28. end
  29.  
  30. print("Peripherals found")
  31.  
  32. local targetPressure = 0
  33.  
  34. if disk.getLabel(diskSide) ~= "Floppy Disk" and disk.getLabel(diskSide) ~= nil then
  35.     print(disk.getLabel(diskSide))
  36.     targetPressure = tonumber(disk.getLabel(diskSide))
  37. end
  38.  
  39. local currentPressure = 0
  40. local change = true
  41.  
  42. monitor.clear()
  43.  
  44. while true do
  45.  
  46.     if change then
  47.         monitor.clear()
  48.  
  49.         currentPressure = compressor.getPressure()
  50.  
  51.         if currentPressure < targetPressure then
  52.             rs.setOutput(outSide, true)
  53.             --print(currentPressure)
  54.         else
  55.             rs.setOutput(outSide, false)
  56.         end
  57.  
  58.         monitor.setBackgroundColor(colors.black)
  59.  
  60.         monitor.setCursorPos(1, 3)
  61.         monitor.setTextColor(colors.red)
  62.         monitor.write("-")
  63.  
  64.         monitor.setCursorPos(7, 3)
  65.         monitor.setTextColor(colors.green)
  66.         monitor.write("+")
  67.  
  68.         local newString = string.format("%.1f", targetPressure)
  69.  
  70.         monitor.setCursorPos((math.ceil(3 - (newString:len())/2))+1, 3)
  71.         monitor.setTextColor(colors.white)
  72.         monitor.write(newString)
  73.     end
  74.  
  75.     os.startTimer(.1)
  76.  
  77.     local _1, _2, xpos, ypos = os.pullEvent()
  78.    
  79.     if currentPressure ~= compressor.getPressure() then
  80.         change = true
  81.     end
  82.  
  83.     if xpos == 1 and ypos == 3 then
  84.         change = true
  85.         targetPressure = targetPressure - 0.1
  86.  
  87.         disk.setLabel(diskSide, tostring(targetPressure))
  88.  
  89.     elseif xpos == 7 and ypos == 3 then
  90.         change = true
  91.         targetPressure = targetPressure + 0.1
  92.  
  93.         disk.setLabel(diskSide, tostring(targetPressure))
  94.     end
  95.  
  96. end
Add Comment
Please, Sign In to add comment