:sigh: here, try this, wrote it a long time ago when learning cc, just tweaked it a bit and added comments for you…
--make some vars to let us easily adjust the times we want the lights to go on and off
local lightsOffTime=6 --6am
local lightsOnTime=20 --8pm (8 + 12)
--this function takes one parameter, time, and waits until that time to return
local function waitUntilTime(time)
--make an alarm set for time
local alarm=os.setAlarm(time)
while true do
--wait for the alarm event
local eventType, param=os.pullEvent("alarm")
--is it MY alarm?
if param==alarm then
return --yawp, exit
end
end
end
--necessary to give the computer's clock time to set when run from startup
--on bootup it's 0, but it corrects after first yield
os.sleep(0)
--grab current time
local timeNow=os.time()
--if it's later than lightsOffTime and earlier than lightsOnTime...
if timeNow>=lightsOffTime and timeNow<=lightsOnTime then
--...then it's day now, wait for night
waitUntilTime(lightsOnTime)
end
rs.setOutput("left", true)
--start our loop
while true do
--wait for day
waitUntilTime(lightsOffTime)
rs.setOutput("left",false)
--wait for night
waitUntilTime(lightsOnTime)
rs.setOutput("left",true)
end
if you want to be able to use the computer for other stuff while that runs in the background, save it as "lightControl" and put this in your startup script. If you have anything else in startup,
this must be last! Anything after this in startup won't happen at all.
term.clear()
term.setCursorPos(1,1)
parallel.waitForAny(
function() shell.run("shell") end,
function() shell.run("lightControl") end
)