speedSpider3

CC Countdown Redstone Clock

Aug 20th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. tArgs = {...}
  2. if #tArgs < 2 then
  3.   print("Usage: clocker <seconds> <output side> [monitor] [monitor side]")
  4.   print("If a monitor exists, a side must be provided")
  5.   print("Ex: clocker 10 left true right")
  6.   return
  7. end
  8.  
  9. TIME = tonumber(tArgs[1])
  10. if TIME < 2 then
  11.   print("Seconds must be greater than 1")
  12.   return
  13. end
  14.  
  15. OUTPUT = tArgs[2]
  16. MONITOR = false
  17. M_SIDE = "right"
  18.  
  19. if #tArgs > 2 then
  20.   if #tArgs < 4 then
  21.     print("Usage: clocker <seconds> <output side> [monitor] [monitor side]")
  22.     print("If a monitor exists, a side must be provided")
  23.     print("Ex: clocker 10 left true right")
  24.     return
  25.   end
  26.   MONITOR = true
  27.   M_SIDE = tArgs[4]
  28. end
  29.  
  30. running = true
  31. m = peripheral.wrap(M_SIDE)
  32. while running do
  33.  local time = TIME
  34.  while time >= 0 do
  35.   print(time.." seconds remaining")
  36.   if MONITOR then
  37.     m.clearLine()
  38.     m.setCursorPos(1,1)
  39.     m.write(time)
  40.   end
  41.   local first = os.startTimer(1)
  42.   while true do
  43.    local event, timerID = os.pullEvent("timer")
  44.    if timerID == first then
  45.      time = time - 1
  46.      break
  47.    end
  48.   end
  49.  end
  50.  local second = os.startTimer(1)
  51.  rs.setAnalogOutput(OUTPUT, 15)
  52.  while true do
  53.   local event, timerID = os.pullEvent("timer")
  54.   if timerID == second then
  55.    break
  56.   end
  57.  end
  58.  rs.setAnalogOutput(OUTPUT, 0)
  59. end
Add Comment
Please, Sign In to add comment