Advertisement
hevohevo

CC: open_send0

Apr 30th, 2016
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. -- open_send0
  2. -- 遠隔操作で扉を開けるプログラム(メッセージ送信、リモコン側)
  3.  
  4. -- Config
  5. local id = 65535  -- 送信先ID
  6. local open_msg = "Open"  -- 開くメッセージ
  7.  
  8. -- Functions
  9. function init()
  10.   term.clear()
  11.   term.setCursorPos(1,1)
  12.   print("[o]pen")
  13.   print("[q]uit")
  14. end
  15.  
  16. -- Main
  17. rednet.open("back")  -- ポケットコンピュータは後ろ側にモデムがある
  18.  
  19. while true do
  20.   init()
  21.   local event, moji = os.pullEvent("char")
  22.   print(moji)
  23.  
  24.   if moji == "o" then  -- もしmojiが"o"ならば、
  25.     print("send msg: [Open]")
  26.     rednet.send(id, open_msg)  -- メッセージを送信
  27.  
  28.   elseif moji == "q" then  -- もし mojiが"q"ならば、
  29.     print("quit program")
  30.     break  -- while無限ループを抜け出す
  31.  
  32.   else  -- そうでなければ、
  33.     print("wrong moji")
  34.   end
  35.  
  36.   os.sleep(2)
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement