Advertisement
CCHacker132

Television Receiver (Outsource)

Jun 18th, 2021
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open('bottom')
  2. local monitorScan = {peripheral.find('monitor')}
  3. local speakers = {peripheral.find('speaker')}
  4. local idr = 14
  5.  
  6. local monitors={}
  7.  
  8. local monitorList={'top'}
  9.  
  10. for i,v in pairs(monitorScan) do
  11.     local isValid = false
  12.     for ii,vv in pairs(monitorList) do
  13.         if peripheral.getName(v)==(vv) then
  14.             isValid=true
  15.         end
  16.     end
  17.     if isValid then
  18.         table.insert(monitors,v)
  19.     end
  20. end
  21.  
  22. for i,v in pairs(monitors) do
  23.     v.setTextScale(0.5)
  24.     v.setBackgroundColor(colors.black)
  25.     v.clear()
  26.     v.setBackgroundColor(colors.gray)
  27.     v.setTextColor(colors.green)
  28.     v.setCursorPos(2,1)
  29.     v.clearLine()
  30.     v.write('Woodland Broadcasting')
  31.     v.setBackgroundColor(colors.black)
  32. end
  33.  
  34. function drawScreen(monitor,image)
  35.     local oldTerm = term.redirect(monitor)
  36.     paintutils.drawImage(image,5,4)
  37.     term.redirect(oldTerm)
  38. end
  39.  
  40. function playNote(speaker,details)
  41.     speaker.playNote(details[1],details[2])
  42. end
  43.  
  44. while true do
  45.     local id,data,type=rednet.receive()
  46.     if id == idr and data and type then
  47.         if type == '0' then
  48.             for i,v in pairs(monitors) do
  49.                 drawScreen(v,data)
  50.             end
  51.         elseif type == '1' then
  52.             for i,v in pairs(speakers) do
  53.                 playNote(v,data)
  54.             end
  55.         end
  56.     end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement