Advertisement
albrat

Turtle Wireless Control

Jun 29th, 2013
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. local code = 0  -- set the key code to 0
  2. local check = "" -- Set check to blank string
  3. local tid = 24  -- this is our turtle's ID that we want to control.
  4. rednet.open("top") -- my modem is on the top of the computer
  5.  
  6. -- handy little bit of code that outputs the ID of the computer on every startup.
  7. local cmpid = os.getComputerID()  
  8. print(cmpid)
  9.  
  10. function test()  --  Function to get key press
  11.   check, code = os.pullEvent("key")
  12. end
  13.  
  14. function rectur()  -- Function to recieve message
  15.     sid, msg = rednet.receive(1)
  16.     if sid == nil then
  17.         print("Turtle destroyed or out of range")
  18.     end
  19. end
  20.  
  21.  
  22. while true do -- infinite loop
  23.  
  24.   test()  -- Get the keypress. I made it a function because I thought it would be called multiple times.
  25.  
  26.   if code == 200 then  -- 200 is the up arrow
  27.     rednet.send(tid, "forward")
  28.     rectur()
  29.    
  30.   elseif code == 203 then -- 203 is the left arrow
  31.     rednet.send(tid, "left")
  32.     rectur()
  33.    
  34.   elseif code == 205 then -- 205 is the right arrow
  35.     rednet.send(tid, "right")
  36.     rectur()
  37.    
  38.   elseif code == 208 then -- 208 is the down arrow
  39.     rednet.send(tid, "back")
  40.     rectur()
  41.    
  42.   elseif code == 54 then  -- 54 is the shift key
  43.     rednet.send(tid, "up")
  44.     rectur()
  45.    
  46.   elseif code == 157 then -- 157 is the CTRL key
  47.     rednet.send(tid, "down")
  48.     rectur()
  49.    
  50.   elseif code == 28 then -- 28 is the enter key
  51.     rednet.send(tid, "dig")
  52.     rectur()
  53.    
  54.   end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement