Advertisement
Zantag

lightDisplay

Sep 3rd, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. os.loadAPI("lightList")
  2.  
  3. local lightIDs = lightList.getLightIDs()
  4. local lightPeriphs = {}
  5.  
  6. local black = 0
  7. local white = 0xFFFFFF
  8. local gray = 0xBBBBBB
  9.  
  10. local redstoneSide = "top"
  11. function initLightPeriphs()
  12. for i = 1, #lightIDs do
  13. lightPeriphs[i] = peripheral.wrap("glowstone_illuminator_"..lightIDs[i])
  14. if lightPeriphs[i] == nil then
  15. print("Missing Light: " .. lightIDS[i])
  16. end
  17. end
  18. end
  19.  
  20. function light(i, color)
  21. if i >= 1 and i <= #lightPeriphs then
  22.  
  23. if (lightPeriphs[i] ~= nil) then
  24. lightPeriphs[i].setColor(color)
  25. else
  26. print("Light ID: " .. i .. " is null")
  27. end
  28.  
  29. end
  30. end
  31.  
  32. function allBlack()
  33. for i = 1, #lightIDs do
  34. light(i, black)
  35. end
  36. end
  37. function allWhite()
  38. for i = 1, #lightIDs do
  39. light(i, white)
  40. end
  41. end
  42.  
  43. function LightChaser(offSet, whiteLightWidth, GreyLightWidth, blackLightWidth)
  44. currIndex = -50 + offSet
  45. while currIndex <= #lightIDs do
  46. for a = 1, whiteLightWidth do
  47. currIndex = currIndex + 1
  48. light(currIndex, white)
  49. end
  50. for b = 1, GreyLightWidth do
  51. currIndex = currIndex + 1
  52. light(currIndex, gray)
  53. end
  54. for c = 1, blackLightWidth do
  55. currIndex = currIndex + 1
  56. light(currIndex, black)
  57. end
  58. end
  59. end
  60.  
  61. function lightChaserHelper(repeatNumber, sleepAmt, offSet, whiteLightWidth, GreyLightWidth, blackLightWidth)
  62. for i = 1, repeatNumber do
  63. LightChaser(i+offSet, whiteLightWidth, GreyLightWidth, blackLightWidth)
  64. sleep(sleepAmt)
  65. end
  66. end
  67.  
  68. function lightToggle(toggleTimes, sleepAmt)
  69. for i = 1, toggleTimes do
  70. allBlack()
  71. sleep(sleepAmt)
  72. allWhite()
  73. sleep(sleepAmt)
  74. end
  75. end
  76.  
  77. initLightPeriphs()
  78. function main()
  79. allBlack()
  80. while true do
  81. r,s = os.pullEvent()
  82. if r == "redstone" then
  83. v = redstone.getBundledInput(redstoneSide)
  84. print("V: " .. v)
  85. if v == 0 then
  86. allBlack()
  87. elseif v == 1 then
  88. allWhite()
  89. elseif v == 2 then
  90. lightChaserHelper(10, 0.2, 0, 5, 1, 7)
  91. elseif v == 3 then
  92. lightChaserHelper(10, 0.4 0, 3, 1, 5)
  93. elseif v == 4 then
  94. lightChaserHelper(10, 0.4 0, 2, 1, 3)
  95. elseif v == 5 then
  96. lightToggle(5, 0.25)
  97. elseif v == 6 then
  98. allBlack()
  99. local flag = true
  100. while flag do
  101. r2,s2 = os.pullEvent()
  102. if r == "redstone" then
  103. v2 = redstone.getBundledInput(redstoneSide)
  104. if v2 == 1 then
  105. allWhite()
  106. elseif v2 == 2 then
  107. allBlack()
  108. elseif v2 == 3 then
  109. flag = false
  110. end
  111. end
  112. end
  113. end
  114. end
  115. end
  116. end
  117.  
  118. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement