Advertisement
colhaydutu

musicv3-2

Sep 7th, 2023 (edited)
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. local tbl = {}
  2. local isRedstoneSignalOn = false
  3. local modem = peripheral.wrap("left")
  4. modem.open(11)
  5. local function initializeLamps()
  6. for a, v in pairs(peripheral.getNames()) do
  7. if peripheral.getType(v) == "colorful_lamp" then
  8. tbl[#tbl + 1] = peripheral.wrap(v)
  9. end
  10. end
  11. end
  12.  
  13. local function getRandomColor()
  14. return math.random(0, 32767)
  15. end
  16.  
  17. local function applyRandomColors()
  18. for i = 1, #tbl do
  19. tbl[i].setLampColor(getRandomColor())
  20. end
  21. end
  22.  
  23. local function turnOffLamps()
  24. for i = 1, #tbl do
  25. tbl[i].setLampColor(32767)
  26. end
  27. end
  28.  
  29. local function checkRedstoneSignal()
  30. while true do
  31. local redstoneInput = redstone.getInput("back")
  32. if redstoneInput then
  33. if not isRedstoneSignalOn then
  34. isRedstoneSignalOn = true
  35. applyRandomColors()
  36. end
  37. else
  38. if isRedstoneSignalOn then
  39. isRedstoneSignalOn = false
  40. turnOffLamps()
  41. end
  42. end
  43. sleep(0.3)
  44. end
  45. end
  46.  
  47. initializeLamps()
  48.  
  49. parallel.waitForAll(checkRedstoneSignal, function()
  50. while true do
  51. if isRedstoneSignalOn then
  52. sleep(0.6)
  53. applyRandomColors()
  54. else
  55. turnOffLamps()
  56. sleep(0.6)
  57. end
  58. end
  59. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement