LayZee

ComputerCraft lzLights

Oct 16th, 2013
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. --[[
  2.       lzLights v0.1
  3.       (C) LayZee 2013
  4. --]]
  5.  
  6. local times = {
  7.     sunset = 12,
  8.     sunrise = 24
  9. }
  10.  
  11. local function waitFor (time)
  12.   local alarm = os.setAlarm(time)
  13.  
  14.   repeat
  15.     local _, id = os.pullEvent("alarm")
  16.   until id == alarm
  17. end
  18.  
  19. local function lightsOnAtSunset ()
  20.   waitFor(times.sunset)
  21.  
  22.   --Turn lights on
  23.   --rs.setOutput("back", true) --or something
  24. end
  25.  
  26. local function lightsOffAtSunrise ()
  27.   waitFor(times.sunrise)
  28.  
  29.   --Turn lights off
  30.   --rs.setOutput("back", false) --or something
  31. end
  32.  
  33. --Main program
  34. while true do
  35.   parallel.waitForAny(lightsOffAtSunrise, lightsOnAtSunset)
  36. end
Advertisement
Add Comment
Please, Sign In to add comment