Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local computer = require("computer")
- local gpu = component.gpu
- local event = require("event")
- local b_color, f_color = gpu.getBackground()
- local modem;
- local powerrobot = math.ceil(0);
- local power1robot = math.floor(0 / 10);
- local indicatorrobot = "";
- if component.isAvailable("modem") then
- modem = component.modem
- else
- error("Этой программе требуется беспроводной модем для работы!")
- end
- print('Введите ключ')
- local port = 512
- local keyWord = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" .. io.read() .. "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
- require("term").clear()
- modem.open(port)
- -------------------------------------------------------------------------------------
- local commands = {
- [17] = {
- messageToRobot = "forward",
- screenText = "↑",
- },
- [31] = {
- messageToRobot = "back",
- screenText = "↓",
- },
- [30] = {
- messageToRobot = "turnLeft",
- screenText = "←",
- },
- [32] = {
- messageToRobot = "turnRight",
- screenText = "→",
- },
- [57] = {
- messageToRobot = "up",
- screenText = "▲",
- },
- [42] = {
- messageToRobot = "down",
- screenText = "▼",
- },
- [47] = {
- messageToRobot = "use",
- screenText = ">",
- },
- [46] = {
- messageToRobot = "swing",
- screenText = "<",
- },
- [14] = {
- messageToRobot = "exit",
- screenText = "",
- },
- [19] = {
- messageToRobot = "redstone",
- screenText = "Приказываю роботу включить/выключить редстоун вокруг себя",
- },
- }
- function fill(x,y,w,h,cb,cf,t)
- gpu.setBackground(cb)
- gpu.setForeground(cf)
- gpu.fill(x,y,w,h,t)
- gpu.setBackground(b_color)
- gpu.setForeground(f_color)
- end
- function set(x,y,cb,cf,t)
- gpu.setBackground(cb)
- gpu.setForeground(cf)
- gpu.set(x,y,t)
- gpu.setBackground(b_color)
- gpu.setForeground(f_color)
- end
- local function send()
- while true do
- local eventData = { event.pull() }
- if eventData[1] == "key_down" then
- local oneprocent = computer.maxEnergy() /100;
- local power = math.ceil(computer.energy() / oneprocent);
- local power1 = math.floor(computer.energy() / oneprocent / 10);
- local indicator = "";
- if power1>=9 then
- indicator="█"
- elseif power1>=7 then
- indicator="▆"
- elseif power1>=5 then
- indicator="▅"
- elseif power1>=3 then
- indicator="▃"
- elseif power1>=1 then
- indicator="▂"
- elseif power1>=0 then
- indicator="▁"
- end
- gpu.fill(2,2,78,9," ")
- gpu.set(2, 2, "Планшет: " .. indicator .. power .. "%" )
- gpu.set(2, 3, "Робот: " .. indicatorrobot .. powerrobot .. "%" )
- gpu.set(69, 10, "Кнопка:" .. eventData[4])
- if commands[eventData[4]] then
- gpu.set(79, 10, commands[eventData[4]].screenText .. "" )
- modem.broadcast(port, keyWord, commands[eventData[4]].messageToRobot)
- if commands[eventData[4]].messageToRobot == "exit" then
- return
- end
- end
- end
- if eventData[1] == "modem_message" and eventData[4] == port and eventData[6] == keyWord then
- powerrobot = math.ceil(eventData[7])
- power1robot = math.floor(eventData[7] / 10);
- indicatorrobot = "";
- if power1robot>=9 then
- indicatorrobot="█"
- elseif power1robot>=7 then
- indicatorrobot="▆"
- elseif power1robot>=5 then
- indicatorrobot="▅"
- elseif power1robot>=3 then
- indicatorrobot="▃"
- elseif power1robot>=1 then
- indicatorrobot="▂"
- elseif power1robot>=0 then
- indicatorrobot="▁"
- end
- end
- end
- end
- local function main()
- send()
- end
- -------------------------------------------------------------------------------------
- main()
- -------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment