Advertisement
Guest User

ComputerCraft Compoud Timer

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