Advertisement
koki2000

belépés és kilépés érzékelő

Mar 30th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. x =10
  2.  
  3. left = false
  4. right = false
  5. route = 0
  6.  
  7. sides = {"left", "right"}
  8.  
  9. m = peripheral.wrap("top");
  10.  
  11. function mprint(text)
  12.  m.clear()
  13.  m.setCursorPos(1, 1)
  14.  m.write(text)
  15. end
  16.  
  17. function rsdetect()
  18.  if ( rs.getInput(sides[1]) ) then
  19. --  mprint("bal oldal aktív")
  20.   inout(sides[1])
  21.  elseif (rs.getInput(sides[2]) ) then
  22. --  mprint("jobb oldal aktív")
  23.   inout(sides[2])
  24.  end
  25. end
  26.  
  27. function inout(side)
  28.   if ( side == "left" and left == false  and right == false) then
  29.    left = true
  30.   elseif ( left == true and side == "right" ) then
  31.    mprint("enter")
  32.    left = false
  33.    right = false
  34.   end
  35.  
  36.   if ( side == "right" and right == false  and left == false) then
  37.    right = true
  38.   elseif ( right == true and side == "left" ) then
  39.    mprint("exit")
  40.    left = false
  41.    right = false
  42.   end
  43. end
  44.  
  45. while ( true ) do
  46.  rsdetect()
  47.  x = x - 1
  48.  if ( x == 1 ) then
  49.   m.clear()
  50.  end
  51.  sleep(.5)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement