Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.unloadAPI("sensors")
- os.loadAPI("rom/apis/sensors")
- local receiverID = 1 --Change this to the id of the computer controlling your lighting system
- scontrol = sensors.getController()
- print("Attaching Sensor Controller on "..scontrol.." side")
- print("Press X to exit application")
- avSensors = sensors.getSensors(scontrol)
- sUseSensor = avSensors[1] -- You need to change the index here to match the index of the sensor containing the World Sensor
- -- Module Card. SMP ComputerCraft is a bit glitched in that all sensors are named 'Sensor' even if
- -- manually changed. Use the /ccSensors/console application to find the id of the sensor to use
- avProbes = sensors.getProbes(scontrol, sUseSensor)
- sWorldProbe = avProbes[1] -- Probe index numbers are static, you can either assign variables like this or just go straight to
- sAreaProbe = avProbes[2] -- the area probe index (which is 2) as the Area Probe contains the light level data.
- sBiomeProbe = avProbes[3]
- do while true
- --[[ Since I use a timer (set at 1 minute interval) to pulse the sensor 'controller' computer, I use the os.pullEvent() to
- detect the redstone signal (or the exit keystroke) and then run the sensor routine. You could also use the built in Timer
- function to simulate the same sort of thing (though it is slightly less reliable imo) ]]--
- local event,param1 = os.pullEvent()
- if event == "redstone" then
- if rs.getInput("back") == true then -- Change "back" to whatever side you have the redstone pulse coming in
- spReading = sensors.getReading2(scontrol,sUseSensor,sAreaProbe)
- sprLightLevel = spReading["LightLevel"]
- --[[ Change the rednet.open("right") statement to reflect what side the modem is on your computer ]]--
- if tonumber(sprLightLevel) <= 8 then -- the getReading2 function returns all values as strings, you need to
- rednet.open("right") -- convert the string to a number to properly compare the light level
- rednet.send(receiverID, "lightson")
- rednet.close("right")
- else
- rednet.open("right")
- rednet.send(receiverID, "lightsoff")
- rednet.close("right")
- end
- end
- elseif event == "char" then -- This just detects key presses and, if the proper key is pressed, exits the application
- if (param1 == "x") or (param1 == "X")
- term.clear()
- term.setCursorPos(1,1)
- print("Bye")
- return
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement