И снова доброго времени суток!
Написал и недавно допили прогу по упровлению светом с помощью RedLogic!
Команда для скачивания: pastebin get -f uZFEL62c light.lua
Вот код:
component = require("component");
side = require("sides");
color = require("colors");
rs = component.redstone;
--funcs-------------------------------------------------------------------------------------------------------------
function hlp()
os.execute('clear');
check();
print('\n-------------------------------------------------',
'\nlight_1_on - to switсh on a light_1;',
'\nlight_1_off - to switсh off a light_1;',
'\nlight_2_on - to switсh on a light_2;',
'\nlight_2_off - to switсh of a light_2;',
'\nall_on - switсh on all light;',
'\nall_off - to switсh off all light;',
'\n-------------------------------------------------\n');
end
--
function check()
local component = require('component');
local light_1 = component.redstone.getBundledInput(2, 14);
local light_2 = component.redstone.getBundledInput(2, 4);
if light_1 <= 255 and light_1 > 15 then
print('Light_1 \x1b[32m++\x1b[0m ');
elseif light_1 >= 0 and light_1 < 15 then
print('Light_1 \x1b[31m--\x1b[0m ');
end
if light_2 <= 255 and light_2 > 15 then
print('Light_2 \x1b[32m++\x1b[0m');
elseif light_2 >= 0 and light_2 < 15 then
print('Light_2 \x1b[31m--\x1b[0m');
end
end
--
function _light_1_on()
rs.setBundledOutput(2, 14, 255);
os.execute('clear');
check();
end
--
function _light_1_off()
rs.setBundledOutput(2, 14, 0);
os.execute('clear');
check();
end
--
function _light_2_on()
rs.setBundledOutput(2, 4, 255);
os.execute('clear');
check();
end
--
function _light_2_off()
rs.setBundledOutput(2, 4, 0);
os.execute('clear');
check();
end
--
function _all_off()
rs.setBundledOutput(2, 4, 0);
rs.setBundledOutput(2, 14, 0);
os.execute('clear');
check();
end
--
function _all_on()
rs.setBundledOutput(2, 4, 255);
rs.setBundledOutput(2, 14, 255);
os.execute('clear');
check();
end
--main--------------------------------------------------------------------------------------------------------------
os.execute('clear');
print('Enter \'help\'');
local cmds = {
light_1_on = _light_1_on,
light_1_off = _light_1_off,
light_2_on = _light_2_on,
light_2_off = _light_2_off,
all_on = _all_on,
all_off = _all_off,
help = hlp
}
local term = require("term");
while true do
term.write('> ');
cmd = term.read();
if cmd == false then
print("Exiting!")
os.exit()
end
cmd, _ = cmd:gsub("\n","");
if type(cmds[cmd]) == "function" then
cmds[cmd]();
else
print("No such command: " .. cmd);
end
end
(На лампе №1 нет контакта, но и так понятно что всё работает)
Если преодолею лень и перестану тупить то возможно у этой проги появится GUI!