hevohevo

CC: open_send1

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