Guest User

CC timer

a guest
May 8th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.20 KB | None | 0 0
  1. -- shell.run("timer")
  2. local tick = 0
  3. local backOutputColor = 0
  4. local firstTime = true
  5.  
  6. while true do
  7.     if not rs.getInput("front") then   
  8.         if firstTime then
  9.             print("------------")
  10.             print("Timer Active")
  11.             print("------------")
  12.             firstTime = false
  13.         end
  14.    
  15.         -- Timers for back output.
  16.         backOutputColor = 0
  17.    
  18.         if tick ~= 0 then
  19.             -- Pulse every:
  20.             -- 1/10 Second
  21.             if math.fmod(tick, 2) == 0 then
  22.                 backOutputColor = backOutputColor + colors.white
  23.             end
  24.            
  25.             -- 1/2 Second
  26.             if math.fmod(tick, 5) == 0 then
  27.                 backOutputColor = backOutputColor + colors.orange
  28.             end
  29.            
  30.             -- 1 Second
  31.             if math.fmod(tick, 10) == 0 then
  32.                 backOutputColor = backOutputColor + colors.magenta
  33.             end
  34.  
  35.             -- 2 Second        
  36.             if math.fmod(tick, 20) == 0 then
  37.                 backOutputColor = backOutputColor + colors.lightBlue
  38.             end
  39.  
  40.             -- 3 Second        
  41.             if math.fmod(tick, 30) == 0 then
  42.                 backOutputColor = backOutputColor + colors.yellow
  43.             end
  44.  
  45.             -- 4 Second        
  46.             if math.fmod(tick, 40) == 0 then
  47.                 backOutputColor = backOutputColor + colors.lime
  48.             end        
  49.  
  50.             -- 5 Second        
  51.             if math.fmod(tick, 50) == 0 then
  52.                 backOutputColor = backOutputColor + colors.pink
  53.             end
  54.  
  55.             -- 10 Second           
  56.             if math.fmod(tick, 100) == 0 then
  57.                 backOutputColor = backOutputColor + colors.gray
  58.             end
  59.  
  60.             -- 20 Second           
  61.             if math.fmod(tick, 200) == 0 then
  62.                 backOutputColor = backOutputColor + colors.lightGray
  63.             end
  64.            
  65.             -- 30 Second           
  66.             if math.fmod(tick, 300) == 0 then
  67.                 backOutputColor = backOutputColor + colors.cyan
  68.             end
  69.  
  70.             -- 1 Minute
  71.             if math.fmod(tick, 600) == 0 then
  72.                 backOutputColor = backOutputColor + colors.purple
  73.             end
  74.  
  75.             -- 5 Minute
  76.             if math.fmod(tick, 3000) == 0 then
  77.                 backOutputColor = backOutputColor + colors.blue
  78.             end
  79.  
  80.             -- 10 Minute
  81.             if math.fmod(tick, 6000) == 0 then
  82.                 print("10 Minutes Complete.")
  83.                 backOutputColor = backOutputColor + colors.brown
  84.             end
  85.  
  86.             -- 20 Minute
  87.             if math.fmod(tick, 12000) == 0 then
  88.                 backOutputColor = backOutputColor + colors.green
  89.             end        
  90.  
  91.             -- 30 Minute
  92.             if math.fmod(tick, 18000) == 0 then
  93.                 backOutputColor = backOutputColor + colors.red
  94.             end
  95.  
  96.             -- 1 Hour
  97.             if math.fmod(tick, 36000) == 0 then
  98.                 print("1 Hour Complete")
  99.                 backOutputColor = backOutputColor + colors.black
  100.             end
  101.         end
  102.        
  103.         -- Set Bundled Cable backoutput
  104.         redstone.setBundledOutput("back", backOutputColor)
  105.        
  106.         -- Add timers for bundled output to any other side.
  107.        
  108.         -- Base time interval (1/10 second) == 1 Redstone tick == 2 Game Ticks
  109.         sleep(.1)
  110.        
  111.         -- Reset tick count in case there is a max int size
  112.         if tick == 36000 then
  113.             tick = 0           
  114.         end
  115.         tick = tick + 1
  116.     else
  117.         term.clear()
  118.         term.setCursorPos(1,1)
  119.         timerOutput("back", 0)
  120.         print("Timer Disabled, Redstone Low in front to enable.")
  121.         os.pullEvent("redstone")
  122.         if not rs.getInput("front") then   
  123.             firstTime = true
  124.             tick = 0
  125.         end
  126.     end
  127. end
  128.  
  129. -- Colors API Cheat Sheet
  130. --[[
  131. colors.white
  132. colors.orange
  133. colors.magenta
  134. colors.lightBlue
  135. colors.yellow
  136. colors.lime
  137. colors.pink
  138. colors.gray
  139. colors.lightGray
  140. colors.cyan
  141. colors.purple
  142. colors.blue
  143. colors.brown
  144. colors.green
  145. colors.red
  146. colors.black
  147. ]]--
Advertisement
Add Comment
Please, Sign In to add comment