Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Variables ---
- pos = "rien" --- Position de l'ascenseur | up - down
- appel = "rien" --- Detection de l'appel d'ascenseur | up - down
- --- Fonctions ---
- function detectPos()
- if rs.getBundledInput("back") == 2 then
- pos = "down"
- elseif rs.getBundledInput("back") == 2048 then
- pos = "up"
- else
- pos = 0
- end
- end
- function detectCall()
- if rs.getBundledInput("right") == 16384 then
- appel = "down"
- elseif rs.getBundledInput("right") == 8192 then
- appel = "up"
- else
- appel = 0
- end
- end
- function elevatorUp()
- blocs = 20
- while blocs ~= 0 do
- rs.setOutput("top", true)
- sleep(0.5)
- rs.setOutput("top", false)
- sleep(0.5)
- blocs = blocs - 1
- print("UP")
- end
- blocs = 20
- end
- function elevatorDown()
- blocs = 20
- while blocs ~= 0 do
- rs.setOutput("front", true)
- sleep(0.5)
- rs.setOutput("front", false)
- sleep(0.5)
- blocs = blocs - 1
- print("DOWN")
- end
- blocs = 20
- end
- function afficheur()
- print("pos :"..pos)
- print("appel :"..appel)
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- --- Procédure ---
- while true do
- detectPos()
- detectCall()
- afficheur()
- if pos == "up" and appel == "up" then
- elevatorDown()
- elseif pos == "up" and appel == "down" then
- elevatorDown()
- elseif pos == "down" and appel == "down" then
- elevatorUp()
- elseif pos == "down" and appel == "up" then
- elevatorUp()
- else
- sleep(1)
- end
- sleep(0.5)
- clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment