Advertisement
Himeki

Day-Night clock

Sep 30th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. mon = peripheral.wrap( "left" )
  2. readout = "Awaiting time shift."
  3. side = "back" --redstone output side
  4.  
  5. mon.write(readout)
  6. print(readout)
  7. time1 = 6.00
  8. time2 = 18.00
  9. event = "blank"
  10. input = "blank"
  11. function clear()
  12.     term.clear()
  13.     term.setCursorPos(1,1)
  14. end
  15.  
  16. function rnd()  --reset and display
  17.     mon.clear()
  18.     mon.setCursorPos(1,1)
  19.     sunrise = os.setAlarm(time1)
  20.     sunset = os.setAlarm(time2)
  21.     print(readout)
  22.     mon.write(readout)
  23. end
  24.  
  25. function dbug()
  26.     print("event:" .. event)
  27.     print("input:" .. input)
  28.     print("readout:" .. readout)
  29. end
  30.  
  31. rnd()
  32.  
  33. while true do
  34.     event, input = os.pullEvent("alarm")
  35.     if input == sunrise then
  36.         redstone.setOutput(side, false)
  37.         readout = "Good Morning."
  38.         rnd()
  39.         -- dbug()
  40.         print("lights out.")
  41.         sleep(1)
  42.     elseif  input == sunset then
  43.         redstone.setOutput(side, true)
  44.         readout = "Good Night."
  45.         rnd()
  46.         -- dbug()
  47.         print("lights on.")
  48.         sleep(1)
  49.     end
  50. end
  51.  
  52. clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement