Advertisement
Darking560

OpenRadio turtle

Jan 30th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.67 KB | None | 0 0
  1. modem = peripheral.wrap("left")
  2. modem.open(123)
  3. local radio = {}
  4. local current = 0
  5. local volume = 0
  6.  
  7. turtle.select(1)
  8. turtle.suck()
  9.  
  10. function switch(nb)
  11.     turtle.select(1)
  12.     turtle.suck()
  13.     if nb ~= 0 then
  14.         turtle.select(nb)
  15.         turtle.drop()
  16.         turtle.select(1)
  17.     end
  18. end
  19.  
  20. while true do
  21.     local event, side, sender, reply, message = os.pullEvent("modem_message")
  22.     if sender == 123 then
  23.         radio = textutils.unserialize(message)
  24.         print(radio["fr"] ..":".. radio["vl"])
  25.         if radio["fr"] ~= current then
  26.             switch(radio["fr"])
  27.             current = radio["fr"]
  28.         end
  29.         if radio["vl"] ~= volume then
  30.             rs.setAnalogOutput("front",radio["vl"])
  31.         end
  32.     end
  33.     sleep(2)
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement