Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- programa para crear un mando a distancia con dos botones
- principal = term.current()
- principal.setCursorPos(1, 1)
- principal.setTextColor(colors.yellow)
- principal.clearLine()
- principal.write("Hay un botón:")
- h = 3
- hw, ww = principal.getSize()
- w = hw-2
- textV = {"Encender", "Apagar"}
- x = 2
- -- first button
- y1 = 3
- window1 = window.create(term.current(),x,y1,w,h)
- window1.setBackgroundColor(colors.green)
- window1.clear()
- --add text
- text = textV[1]
- newX = math.floor((w - #text)/2) + 1
- newY = math.floor(h/2) + 1
- window1.setCursorPos(newX, newY)
- window1.setTextColor(colors.black)
- window1.write(text)
- -- second button
- y2 = y1+h+1
- window2 = window.create(term.current(),x,y2,w,h)
- window2.setBackgroundColor(colors.red)
- window2.clear()
- --add text
- text = textV[2]
- newX = math.floor((w - #text)/2) + 1
- newY = math.floor(h/2) + 1
- window2.setCursorPos(newX, newY)
- window2.setTextColor(colors.black)
- window2.write(text)
- -- start net
- rednet.open("back")
- pcID = 112
- while true do
- event, side, xM, yM = os.pullEvent("mouse_click")
- principal.setCursorPos(1, y2+h+1)
- principal.setTextColor(colors.white)
- principal.clearLine()
- if xM >= 1 and xM <= ww-1 then
- if yM >= y1 and yM <= y1 + h then
- lastText = "Encendido"
- principal.write(lastText.." en")
- rednet.send(pcID,lastText)
- for k = 0,3 do
- principal.write(" "..3-k)
- if k == 3 then
- principal.write("!")
- end
- sleep(1)
- end
- elseif yM >= y2 and yM < y2 + h then
- lastText = "Apagado"
- principal.write(lastText)
- rednet.send(pcID,lastText)
- else
- principal.write(lastText)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement