Advertisement
TeoremaPi

Tablet (2 botones y wifi)

Apr 12th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. principal = term.current()
  2. principal.setCursorPos(1, 1)
  3. principal.setTextColor(colors.yellow)
  4. principal.clearLine()
  5. principal.write("Hay un botรณn:")
  6.  
  7. h = 3
  8. hw, ww = principal.getSize()
  9. w = hw-2
  10.  
  11. textV = {"Encender", "Apagar"}
  12. x = 2
  13.  
  14. -- first button
  15. y1 = 3
  16.  
  17. window1 = window.create(term.current(),x,y1,w,h)
  18. window1.setBackgroundColor(colors.green)
  19. window1.clear()
  20.  
  21. --add text
  22. text = textV[1]
  23. newX = math.floor((w - #text)/2) + 1
  24. newY = math.floor(h/2) + 1
  25. window1.setCursorPos(newX, newY)
  26. window1.setTextColor(colors.black)
  27. window1.write(text)
  28.  
  29.  
  30. -- second button
  31. y2 = y1+h+1
  32.  
  33. window2 = window.create(term.current(),x,y2,w,h)
  34. window2.setBackgroundColor(colors.red)
  35. window2.clear()
  36.  
  37. --add text
  38. text = textV[2]
  39. newX = math.floor((w - #text)/2) + 1
  40. newY = math.floor(h/2) + 1
  41. window2.setCursorPos(newX, newY)
  42. window2.setTextColor(colors.black)
  43. window2.write(text)
  44.  
  45.  
  46. -- start net
  47. rednet.open("back")
  48.  
  49. pcID = 4
  50.  
  51. while true do
  52.  
  53.     event, side, xM, yM = os.pullEvent("mouse_click")
  54.  
  55.     principal.setCursorPos(1, y2+h+1)
  56.     principal.setTextColor(colors.white)
  57.     principal.clearLine()
  58.    
  59.     if xM >= 1 and xM <= ww-1 then
  60.         if yM >= y1 and yM <= y1 + h then
  61.             lastText = "Encendido"
  62.             principal.write(lastText)
  63.  
  64.             rednet.send(pcID,lastText)
  65.  
  66.         elseif yM >= y2 and yM < y2 + h then
  67.             lastText = "Apagado"
  68.             principal.write(lastText)
  69.  
  70.             rednet.send(pcID,lastText)
  71.            
  72.         else
  73.             principal.write(lastText)
  74.         end
  75.     end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement