daily pastebin goal
66%
SHARE
TWEET

CC: rc_send0

hevohevo May 2nd, 2016 (edited) 108 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- rc_send0
  2. -- タートルをラジコンにするプログラム(リモコン側)
  3.  
  4. -- Config
  5. local id = 65535  -- 送信先ID
  6. local left_msg = "strafe_left"
  7. local right_msg = "strafe_right"
  8. local forward_msg = "go_forward"
  9. local back_msg = "go_back"
  10.  
  11. -- Functions
  12. function init()
  13.   term.clear()
  14.   term.setCursorPos(1,1)
  15.   print("  w  ")
  16.   print("a   d")
  17.   print("  s  ")
  18. end
  19.  
  20. -- Main
  21. rednet.open("back")  -- ポケットコンピュータは後ろ側にモデムがある
  22.  
  23. while true do
  24.   init()
  25.   local event, moji = os.pullEvent("char")
  26.   print(moji)
  27.  
  28.   if moji == "w" then  -- もしmojiが"w"ならば、
  29.     rednet.send(id, forward_msg)
  30.   elseif moji == "a" then  -- もしmojiが"c"ならば、
  31.     rednet.send(id, left_msg)
  32.   elseif moji == "d" then  -- もし mojiが"q"ならば、
  33.     rednet.send(id, right_msg)
  34.   elseif moji == "s" then  -- もしmojiが"c"ならば、
  35.     rednet.send(id, back_msg)
  36.  
  37.   else  -- そうでなければ、
  38.     print("wrong moji")
  39.   end
  40.  
  41.   os.sleep(2)
  42. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top