Advertisement
Zantag

lightTower

Jan 5th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. local lightPeriphNames = {}
  2. local lightPeriphs = {}
  3.  
  4. local black = 0
  5. local white = 0xFFFFFF
  6. local gray = 0xBBBBBB
  7. local yellow = 0xFFFF00
  8. local blue = 0x0000FF
  9.  
  10.  
  11. function getPeripherals(type)
  12. for _, name in pairs(peripheral.getNames()) do
  13. if peripheral.getType(name) == type then
  14. table.insert(lightPeriphNames, name)
  15. end
  16. end
  17. end
  18. function initLightPeriphs()
  19. for i = 1, #lightPeriphNames do
  20. lightPeriphs[i] = peripheral.wrap(lightPeriphNames[i])
  21. if lightPeriphs[i] == nil then
  22. print("Missing Light: " .. lightIDS[i])
  23. end
  24. end
  25. end
  26.  
  27.  
  28. function light(i, color)
  29. if i >= 1 and i <= #lightPeriphs then
  30.  
  31. if (lightPeriphs[i] ~= nil) then
  32. lightPeriphs[i].setColor(color)
  33. else
  34. print("Light ID: " .. i .. " is null")
  35. end
  36.  
  37. end
  38. end
  39.  
  40. function allColor(color)
  41. for i = 1, #lightPeriphs do
  42. light(i, color)
  43. end
  44. end
  45. function lightChaserHelper(repeatNumber, sleepAmt, offSet, whiteLightWidth, GreyLightWidth, blackLightWidth)
  46. for i = 1, repeatNumber do
  47. LightChaser(i+offSet, whiteLightWidth, GreyLightWidth, blackLightWidth)
  48. sleep(sleepAmt)
  49. end
  50. end
  51.  
  52. function lightToggle(toggleTimes, sleepAmt)
  53. for i = 1, toggleTimes do
  54. allBlack()
  55. sleep(sleepAmt)
  56. allWhite()
  57. sleep(sleepAmt)
  58. end
  59. end
  60.  
  61.  
  62. function main()
  63. getPeripherals("cofh_thermalexpansion_lamp")
  64. initLightPeriphs()
  65. math.randomseed( os.time() )
  66. local t = 0
  67. local rnd = 0
  68. allColor(blue)
  69. while (true) do
  70. if (os.time() - 1) > t then
  71. t = os.time()
  72. rnd = math.random(1,4)
  73. end
  74. if rnd == 1 then
  75. allColor(blue)
  76. sleep(5)
  77. elseif rnd == 2 then
  78. allColor(yellow)
  79. sleep(5)
  80. elseif rnd == 3 then
  81. local max = math.random(1, 20)
  82. for i = 1, max do
  83. allColor(yellow)
  84. sleep(0.5)
  85. allColor(blue)
  86. sleep(0.5)
  87. end
  88. elseif rnd == 4 then
  89.  
  90. end
  91. sleep(0.2)
  92. end
  93. end
  94.  
  95. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement