Advertisement
Guest User

radio

a guest
May 27th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. os.startTimer(5)
  2. r1 = peripheral.wrap("iron_note_32")
  3. r2 = peripheral.wrap("iron_note_34")
  4. f1 = peripheral.wrap("iron_note_31")
  5. f2 = peripheral.wrap("iron_note_33")
  6. local function rear(inst,pitch)
  7.   r1.playNote(inst,pitch)
  8.   r2.playNote(inst,pitch)
  9. end
  10. local function front(inst,pitch)
  11.   f1.playNote(inst,pitch)
  12.   f2.playNote(inst,pitch)
  13. end
  14. local radios = {}
  15. local function isRadio(msg)
  16.   if type(msg) ~= "table" then
  17.     return false
  18.   end
  19.   if msg.sType ~= "radio" then
  20.     return false
  21.   end
  22.   return true
  23. end
  24.  
  25. print("Scanning for online radio stations...")
  26. while true do
  27.   local tEvent = {os.pullEvent()}
  28.   if isRadio(tEvent[3]) then
  29.     radios[tEvent[3].sChannel] = tEvent[3].sChannel
  30.   end
  31.   if tEvent[1] == "timer" then
  32.     break
  33.   end
  34. end
  35. i = 0
  36. for k,v in pairs(radios) do
  37.   i = i + 1
  38.   print(i..": "..v)
  39. end
  40. write("Connect to: ")
  41. local chan = read()
  42.  
  43. function updateTime()
  44.   if cont.cur ~= ocur then
  45.     ges = cont.all
  46.     cur = cont.cur
  47.     allm = math.floor(ges/60)
  48.     alls = ges%60
  49.     curm = math.floor(cur/60)
  50.     curs = cur%60
  51.     text = string.format("%2i:%2i",curm,curs):gsub(" ","0").." / "..string.format("%2i:%2i",allm,alls):gsub(" ","0").." - "..cont.name
  52.     x,y = term.getCursorPos()
  53.     term.setCursorPos(1,y)
  54.     term.clearLine()
  55.     term.write(text)
  56.     ocur = cur
  57.   end
  58. end
  59. ocur = -1
  60. block = peripheral.find("iron_note")
  61. while true do
  62.   e = {os.pullEvent("bitnet_message")}
  63.   msg = e[3]
  64.   if msg.sType == "radio" and msg.sChannel == chan then
  65.     cont = msg.tMessage
  66.     updateTime()
  67.     for i,v in pairs(cont.notes) do
  68.       if v and v.pitch then
  69.         if (v.inst == 4 and v.pitch <= 20) or (v.inst == 1 and v.pitch <= 12) or (v.inst == 2 and v.pitch <= 6) or (v.int==1 and v.pitch <= 2) then
  70.           pcall(function() rear(v.inst,v.pitch) end)
  71.         else
  72.           pcall(function() front(v.inst,v.pitch) end)
  73.         end
  74.       end
  75.       --pcall(function() block.playNote(v.inst,v.pitch) end)
  76.     end
  77.   end
  78. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement