hevohevo

CC: exercise10_1_receive

May 21st, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. -- exercise10_1_receive
  2. -- ワイヤレス通信メッセージを受信して外部モニターに流す(受信側プログラム)
  3. -- 最初は文字サイズ1で表示し右に流れる。次に文字サイズ2で右に流れる。
  4.  
  5. local mon = peripheral.wrap("top") -- 上側のモニターを使います宣言
  6. rednet.open("right") -- 右のモデムを使います宣言
  7.  
  8. -- ############# Functions ##############
  9. function init()
  10.   mon.setTextColor(colors.white)
  11.   mon.setBackgroundColor(colors.black)
  12.   mon.clear()
  13. end
  14.  
  15. function displayString(x, y, msg)
  16.   mon.setCursorPos(x,y)
  17.   mon.write(msg)
  18. end
  19.  
  20. -- ############### Main ################
  21. while true do
  22.   local id, msg = rednet.receive() -- メッセージを受信するまで待ち続ける
  23.   print(id, msg) --送信元IDとメッセージをターミナル画面に表示
  24.  
  25.   mon.setTextScale(1)
  26.   local xSize, ySize = mon.getSize()
  27.  
  28.   for x=1, xSize do
  29.     init()
  30.     displayString(x,1,msg)
  31.     os.sleep(0.3)
  32.   end
  33.  
  34.   mon.setTextScale(2)
  35.   xSize, ySize = mon.getSize()
  36.  
  37.   for x=1, xSize do
  38.     init()
  39.     displayString(x,1,msg)
  40.     os.sleep(0.3)
  41.   end
  42.  
  43. end
Add Comment
Please, Sign In to add comment