Advertisement
Axow01

Untitled

Aug 13th, 2023 (edited)
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. rednet.open("top")
  2. local speaker = peripheral.wrap("bottom")
  3.  
  4. local function alarm()
  5.     for i = 0, 300, 2 do
  6.         redstone.setAnalogOutput("back", 15)
  7.         speaker.playNote("harp", 3, 4)
  8.         os.sleep(0.5)
  9.         redstone.setAnalogOutput("back", 0)
  10.         os.sleep(0.5)
  11.     end
  12. end
  13.  
  14. local co = nil
  15.  
  16. while true do
  17.     local senderId, Message, protocol = rednet.receive("light_42", 300)
  18.     if Message == true then
  19.         redstone.setAnalogOutput("back", 15)
  20.     elseif Message == false or Message == nil then
  21.         redstone.setAnalogOutput("back", 0)
  22.     elseif Message == "alarm" then
  23.         if not co or coroutine.status(co) == "dead" then
  24.             co = coroutine.create(alarm)
  25.             coroutine.resume(co)
  26.         end
  27.     end
  28.     os.sleep(0.1)  -- Add a short delay to prevent constant looping
  29. end
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement