Guest User

Lift Program KingCoon

a guest
Jan 16th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1.   -- lift control By KingCoon14  (King of the Coons) --
  2.    
  3.     floorSize = 5
  4.     sSide = "left"
  5.     upFreq = 2
  6.     downFreq = 3
  7.     currentFloorCount = rs.getBundledInput("back")
  8.    
  9.     local function down()
  10.         m = peripheral.wrap(sSide)
  11.         m.setFreq(downFreq)
  12.             local nCount = floorSize
  13.             local nPeriod = 1
  14.             for n=1,nCount do
  15.                     redstone.setOutput( sSide, true )
  16.                     sleep( nPeriod / 2 )
  17.                     redstone.setOutput( sSide, false )
  18.                     sleep( nPeriod / 2 )
  19.             end
  20.     end
  21.  
  22.     local function up()
  23.         m = peripheral.wrap(sSide)
  24.         m.setFreq(upFreq)
  25.             local nCount = floorSize
  26.             local nPeriod = 1
  27.             for n=1,nCount do
  28.                     redstone.setOutput( sSide, true )
  29.                     sleep( nPeriod / 2 )
  30.                     redstone.setOutput( sSide, false )
  31.                     sleep( nPeriod / 2 )
  32.             end                    
  33.     end    
  34.  
  35.    
  36. --GUI--
  37.  
  38.     term.clear()
  39.     term.setCursorPos(1,1)
  40.    
  41.    
  42.     print("Lift Control")
  43.    
  44.     term.setCursorPos(18,1)
  45.     print("Current Floor: ", currentFloor)
  46.    
  47.     term.setCursorPos(3,4) 
  48.     write("Requested Floor:")
  49.     toFloor = io.read()
  50.    
  51.     term.clear()
  52.     term.setCursorPos(1,1)
  53.     print("Going to Floor ", toFloor)
  54.    
  55.    
  56. -- Up and Down mechanics --
  57.  
  58. while true do
  59.  
  60.     toFloor = tonumber(toFloor)
  61.     cunnretFloor = tonumber(currentFloor)
  62.    
  63.     if currnetFloorCount == 2048 then
  64.         currentFloor = 1
  65.        
  66.     elseif currnetFloorCount == 2 then
  67.         currentFloor = 2
  68.        
  69.     elseif currnetFloorCount == 4 then
  70.         currentFloor = 3
  71.        
  72.     elseif currnetFloorCount == 8 then
  73.         currentFloor = 4
  74.        
  75.     elseif currnetFloorCount == 16 then
  76.         currentFloor = 5
  77.        
  78.     end
  79.    
  80.     print(currentFloor)
  81.    
  82.     if currentFloor >= toFloor then
  83.         Move = currentFloor - toFloor
  84.         print(Move)
  85.         down(Move)
  86.         os.reboot()
  87.        
  88.     elseif currentFloor <= toFloor then
  89.         move = currentFloor + toFloor
  90.         print(Move)
  91.         up(Move)
  92.         os.reboot()
  93.     end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment