added toggle

This commit is contained in:
navid.sassan 2021-04-02 16:58:49 +02:00
parent 2c7d119400
commit d758bb9e55

View File

@ -51,26 +51,37 @@ function recv()
term.setCursorPos(1, 1) term.setCursorPos(1, 1)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
write('Press "R" to toggle the rainbows.\n') write('Press "T" to toggle the rainbows.\n')
-- xPos, yPos = term.getCursorPos()
-- term.setCursorPos(1,(yPos + 1))
term.write('Rainbows state: ') term.write('Rainbows state: ')
if redstone_toggle_state == true then if redstone_toggle_state == true then
term.setBackgroundColor(colors.green) term.setBackgroundColor(colors.green)
write('On') write('On\n')
elseif redstone_toggle_state == false then elseif redstone_toggle_state == false then
term.setBackgroundColor(colors.red) term.setBackgroundColor(colors.red)
write('Off') write('Off\n')
elseif redstone_toggle_state == nil then elseif redstone_toggle_state == nil then
term.setBackgroundColor(colors.purple) term.setBackgroundColor(colors.purple)
write('Unknown') write('Unknown\n')
end end
print()
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
end end
end end
end end
function key_watcher()
while true do
local event, param = os.pullEvent("key")
if event == "key" then
-- print("Got key: " .. param)
if param == keys.backspace then
break
elseif param == keys.t then
rednet.send(redstone_toggle_id, 'toggle')
end
end
end
end
local sides = peripheral.getNames() local sides = peripheral.getNames()
for i = 1, #sides do for i = 1, #sides do
if peripheral.getType(sides[i]) == "modem" then if peripheral.getType(sides[i]) == "modem" then
@ -82,5 +93,5 @@ end
rednet.open(modemSide) rednet.open(modemSide)
rednet.host("rmm", "master") rednet.host("rmm", "master")
parallel.waitForAny(poll, recv) parallel.waitForAny(poll, recv, key_watcher)
rednet.close(modemSide) rednet.close(modemSide)