Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --By Arongy
- --L_state_# = the state ON/OFF of the light by default.
- --L_id_# = the ID of the light, can be anything you want, but you will have to call the exact same ID when the program ask!
- --L_color_# = the bundled colored wire attach to this light.
- -- CONFIG
- local Debug = true --Turn this to false if your done setting up your lightning system.
- local L_state_1 = "false" local L_id_1 = "outside" local L_color_1 = "blue" local L_side_1 = "bottom"
- local L_state_2 = "false" local L_id_2 = "inside" local L_color_2 = "yellow" local L_side_2 = "bottom"
- local L_state_3 = "false" local L_id_3 = "somewhere1" local L_color_3 = "red" local L_side_3 = "bottom"
- local L_state_4 = "false" local L_id_4 = "somewhere2" local L_color_4 = "lime" local L_side_4 = "bottom"
- -- END CONFIG
- function WriteFile() --Write into the txt file the current states.
- file = io.open("lightstates.txt", "w")
- file:write(L_state_1.."\n"..L_state_2.."\n"..L_state_3.."\n"..L_state_4)
- file:close()
- end
- function ReadFile() --Read into the txt file the current states.
- file = io.open("lightstates.txt", "r")
- L_state_1 = file:read()
- L_state_2 = file:read()
- L_state_3 = file:read()
- L_state_4 = file:read()
- file:close()
- end
- function SwitchStates(light, state) --Verify input and switch the state of a single light.
- if state == "true" or state == "false" then
- if light == L_id_1 then
- L_state_1 = state
- elseif light == L_id_2 then
- L_state_2 = state
- elseif light == L_id_3 then
- L_state_3 = state
- elseif light == L_id_4 then
- L_state_4 = state
- else
- print("This is not a valid ID.") --If the entered ID doesnt exist!
- end
- WriteFile() -- write the states then
- TogglePower() -- toggle the light
- else
- print("This is not a valid state!") --If states is else than 'true' or 'false'
- end
- end
- function SwitchAll(state) --Verify input and switch the state of all light.
- if state == "true" or state == "false" then
- L_state_1 = state
- L_state_2 = state
- L_state_3 = state
- L_state_4 = state
- WriteFile() --write the states then
- TogglePower() --toggle all light
- else
- print("This is not a valid state!") --If states is else than 'true' or 'false'
- end
- end
- function TogglePower() --Will toggle the wire on/off
- ReadFile() --Read into the txt file to get the right states
- shell.run("redset", L_side_1, L_color_1, L_state_1)
- shell.run("redset", L_side_2, L_color_2, L_state_2)
- shell.run("redset", L_side_3, L_color_3, L_state_3)
- shell.run("redset", L_side_4, L_color_4, L_state_4)
- end
- function ShowLightState() --GUI, show the light states
- ReadFile() --Read into the txt file to get the right states
- term.setCursorPos(1,2)
- if Debug == false then
- print("---ID-------STATE-------------") --if debug disabled
- print(" "..L_id_1.." = "..L_state_1)
- print(" "..L_id_2.." = "..L_state_2)
- print(" "..L_id_3.." = "..L_state_3)
- print(" "..L_id_4.." = "..L_state_4)
- elseif Debug == true then
- print("---ID-------STATE---DEBUG-----") --if debug enabled will show the color and side status.
- print(" "..L_id_1.." = "..L_state_1.." ["..L_color_1..", "..L_side_1.."]")
- print(" "..L_id_2.." = "..L_state_2.." ["..L_color_2..", "..L_side_2.."]")
- print(" "..L_id_3.." = "..L_state_3.." ["..L_color_3..", "..L_side_3.."]")
- print(" "..L_id_4.." = "..L_state_4.." ["..L_color_4..", "..L_side_4.."]")
- end
- print("------------------------------")
- end
- function clearText() --Clear the screen leaving the title so its not re-writing again.
- term.setCursorPos(1,2)
- cnt = 0
- while cnt < 15 do --Erase the screen from line 2, keep the title written.
- print(" ")
- cnt = cnt + 1
- end
- ShowLightState() --Show the light states again with new values.
- term.setCursorPos(1,8)
- end
- function header() --Header is called once at computer startup.
- TogglePower() --Toggle the power by default at computer startup
- term.clear()
- ShowLightState()
- term.setCursorPos(1,1)
- textutils.slowPrint("LIGHTNING CONTROL PANEL") --Title, showed once.
- term.setCursorPos(1,2)
- end
- function MainProgram() --The main program where you enter input to select what you wanna do.
- textutils.slowPrint("1-Single 2-All")
- option = read() --Option is to choose if you toggle one or all light at once.
- if option == "1" then --Single
- clearText()
- textutils.slowPrint("Enter an ID?") --wich Light you want to toggle.
- light = read()
- textutils.slowPrint("Enter a state? (true / false)") --states is True for ON false for OFF
- state = read()
- SwitchStates(light, state) -- Switch the states...
- print("Setting "..light.." to "..state)
- elseif option == "2" then --All
- clearText()
- textutils.slowPrint("Enter a state? (true / false)") --Now you simply choose the states you want all light to be.
- state = read()
- SwitchAll(state) --Switch all light to the written state!
- print("Setting all to "..state)
- end
- sleep(2)
- end
- --The Program itself calling function.
- header()
- while true do
- clearText()
- term.setCursorPos(1,8)
- MainProgram() --Call Main program function so it can start!
- end
Add Comment
Please, Sign In to add comment