Advertisement
NAPTlME

Motor2

Jul 5th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. --testFile
  2. --NAPTlME
  3. --RIM motor
  4. --NAPTlME
  5.  
  6. rednet.open('right')
  7.  
  8. print(os.getComputerID())
  9.  
  10. function update()
  11.   --fs.delete("open")
  12.   local y = fs.open('open','w')
  13.   y.writeLine(north)
  14.   y.writeLine(south)
  15.   y.writeLine(east)
  16.   y.writeLine(west)
  17.   y.writeLine(up)
  18.   y.writeLine(down)
  19.   y.close()
  20. end
  21.  
  22. if not fs.exists('open') then
  23.   north = "0"
  24.   south = "0"
  25.   east = "0"
  26.   west = "0"
  27.   up = "0"
  28.   down = "0"
  29.   update()
  30.   os.reboot()
  31. else
  32.   local z = fs.open('open','r')
  33.   north = tonumber(z.readLine())
  34.   south = tonumber(z.readLine())
  35.   east = tonumber(z.readLine())
  36.   west = tonumber(z.readLine())
  37.   up = tonumber(z.readLine())
  38.   down = tonumber(z.readLine())
  39.   z.close()
  40. end
  41. m = peripheral.wrap('bottom')
  42. sleep(0.25)
  43.  
  44.  
  45. function retract(n)
  46.   m.move(n,false,false)
  47. end
  48. function moving()
  49.   if east > 0 then
  50.     east = east - 1
  51.     update()
  52.     retract(5)
  53.   elseif north > 0 then
  54.     north = north - 1
  55.     update()
  56.     retract(2)
  57.     elseif down >0 then
  58.     down = down - 1
  59.     update()
  60.     retract(0)
  61.   elseif up >0 then
  62.     up = up -1
  63.     update()
  64.     retract(1)
  65.   elseif south > 0 then
  66.     south = south - 1
  67.     update()
  68.     retract(3)
  69.   elseif west >0 then
  70.     west = west - 1
  71.     update()
  72.     retract(4)
  73.   end
  74. end
  75. moving()
  76. while true do
  77.   id,msg = rednet.receive()
  78.   if id == 100 then
  79.     if msg == "open" then
  80.       east = 3
  81.       north = 3
  82.       down = 5
  83.       update()
  84.       os.reboot()
  85.     elseif
  86.       msg == "close" then
  87.       up = 5
  88.       south = 3
  89.       west = 3
  90.       update()
  91.       os.reboot()
  92.     end
  93.   end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement