Kierra

Untitled

Jun 21st, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. --- Variables ---
  2.  
  3. pos = "rien"                                                            --- Position de l'ascenseur | up - down
  4. appel = "rien"                                                          --- Detection de l'appel d'ascenseur | up - down
  5.  
  6. --- Fonctions ---
  7.  
  8. function detectPos()
  9.     if rs.getBundledInput("back") == 2 then
  10.         pos = "down"
  11.     elseif rs.getBundledInput("back") == 2048 then
  12.         pos = "up"
  13.     else
  14.         pos = 0
  15.     end
  16. end
  17.  
  18. function detectCall()
  19.     if rs.getBundledInput("right") == 16384 then
  20.         appel = "down"
  21.     elseif rs.getBundledInput("right") == 8192 then
  22.         appel = "up"
  23.     else
  24.         appel = 0
  25.     end
  26. end
  27.  
  28. function elevatorUp()
  29.     blocs = 20
  30.     while blocs ~= 0 do
  31.         rs.setOutput("top", true)
  32.         sleep(0.5)
  33.         rs.setOutput("top", false)
  34.         sleep(0.5)
  35.         blocs = blocs - 1
  36.         print("UP")
  37.     end
  38.     blocs = 20
  39. end
  40.  
  41. function elevatorDown()
  42.     blocs = 20
  43.     while blocs ~= 0 do
  44.         rs.setOutput("front", true)
  45.         sleep(0.5)
  46.         rs.setOutput("front", false)
  47.         sleep(0.5)
  48.         blocs = blocs - 1
  49.         print("DOWN")
  50.     end
  51.     blocs = 20
  52. end
  53.  
  54. function afficheur()
  55.     print("pos :"..pos)
  56.     print("appel :"..appel)
  57.    
  58. end
  59.  
  60. function clear()
  61.     term.clear()
  62.     term.setCursorPos(1,1)
  63. end
  64.    
  65. --- Procédure ---
  66.  
  67. while true do
  68.     detectPos()
  69.     detectCall()
  70.     afficheur()
  71.         if pos == "up" and appel == "up" then
  72.             elevatorDown()
  73.         elseif pos == "up" and appel == "down" then
  74.             elevatorDown()
  75.         elseif pos == "down" and appel == "down" then
  76.             elevatorUp()
  77.         elseif pos == "down" and appel == "up" then
  78.             elevatorUp()
  79.         else
  80.             sleep(1)
  81.         end
  82.     sleep(0.5)
  83.     clear()
  84. end
Advertisement
Add Comment
Please, Sign In to add comment