SHARE
TWEET

CC: rc_receive0

hevohevo May 2nd, 2016 (edited) 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- rc_receive0
  2. -- ラジコンプログラム(タートル側)
  3.  
  4. -- Config
  5. local left_msg = "strafe_left"
  6. local right_msg = "strafe_right"
  7. local forward_msg = "go_forward"
  8. local back_msg = "go_back"
  9.  
  10. -- Functions
  11. function strafeRight()
  12.   turtle.turnRight()
  13.   turtle.forward()
  14.   turtle.turnLeft()
  15. end
  16.  
  17. function strafeLeft()
  18.   turtle.turnLeft()
  19.   turtle.forward()
  20.   turtle.turnRight()
  21. end
  22.  
  23. -- Main
  24. rednet.open("left")  -- 左側に設置したモデムを使うという宣言
  25.  
  26. while true do
  27.   local id, msg = rednet.receive()  -- メッセージを待ち受ける
  28.   print(id, msg)
  29.  
  30.   if msg == left_msg then
  31.     strafeLeft()
  32.   elseif msg == right_msg then
  33.     strafeRight()
  34.   elseif msg == forward_msg then
  35.     turtle.forward()
  36.   elseif msg == back_msg then
  37.     turtle.back()
  38.   else  -- どれでもなければ、
  39.     print("wrong")
  40.   end
  41. end
RAW Paste Data
Top