Advertisement
carlosjuero

ccSensors Light Sensor App 003

Sep 12th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.06 KB | None | 0 0
  1. os.unloadAPI("sensors")
  2. os.loadAPI("rom/apis/sensors")
  3.  
  4. local receiverID = 1230
  5.  
  6. scontrol = sensors.getController()
  7.  
  8. print("Attaching Sensor Controller on "..scontrol.." side")
  9. print("Press X to exit application")
  10.  
  11. avSensors = sensors.getSensors(scontrol)
  12.  
  13. sUseSensor = avSensors[1]
  14.  
  15. avProbes = sensors.getProbes(scontrol, sUseSensor)
  16.  
  17. sWorldProbe = avProbes[1]
  18. sAreaProbe = avProbes[2]
  19. sBiomeProbe = avProbes[3]
  20.  
  21. do while true
  22.     local event,param1 = os.pullEvent()
  23.     if event == "redstone" then
  24.         if rs.getInput("back") == true then
  25.             spReading = sensors.getReading2(scontrol,sUseSensor,sAreaProbe)
  26.             sprLightLevel = spReading["LightLevel"]
  27.  
  28.             if tonumber(sprLightLevel) <= 8 then
  29.                 rednet.open("right")
  30.                 rednet.send(receiverID, "lightson")
  31.                 rednet.close("right")
  32.             else
  33.                 rednet.open("right")
  34.                 rednet.send(receiverID, "lightsoff")
  35.                 rednet.close("right")
  36.             end
  37.         end
  38.     elseif event == "char" then
  39.         if (param1 == "x") or (param1 == "X")
  40.             term.clear()
  41.             term.setCursorPos(1,1)
  42.             print("Bye")
  43.             return
  44.         end
  45.     end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement