Stravides

radio control

Mar 13th, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. --  
  2. --  Stravides Radio Station Program
  3. --  
  4. m = peripheral.wrap("top")
  5. os.unloadAPI("button")
  6. os.loadAPI("button")
  7.  
  8. local currentSide="back"
  9. local currentStation="Trance"
  10. local currentVolume=3
  11.  
  12. local radio1
  13. local radio2
  14. local radio3
  15. local radio4
  16.  
  17. radio1=peripheral.wrap("back")
  18. radio2=peripheral.wrap("right")
  19. radio3=peripheral.wrap("left")
  20. radio4=peripheral.wrap("bottom")
  21.  
  22. function quietplease()
  23.    rs.setAnalogOutput("left",0)
  24.    button.setState("radio1",false)
  25.    rs.setAnalogOutput("right",0)
  26.    button.setState("radio2",false)
  27.    rs.setAnalogOutput("back",0)
  28.    button.setState("radio3",false)
  29.    rs.setAnalogOutput("bottom",0)
  30.    button.setState("radio4",false)
  31. end
  32.  
  33. function play(side,volume)
  34.    quietplease()
  35.    currentSide=side
  36.    currentVolume=volume
  37.    rs.setAnalogOutput(side,volume)
  38.    screen()
  39. end
  40.  
  41. function station(side)
  42. if side=="back" then currentStation="Trance Radio" end
  43. if side=="left" then currentStation="Slay Radio" end
  44. if side=="right" then currentStation="Gamers Radio" end
  45. if side=="bottom" then currentStation="Capitol Radio" end
  46. end
  47.  
  48.  
  49. function addVol()
  50.    if currentVolume<15 then
  51.       currentVolume=currentVolume+1
  52.       play(currentSide,currentVolume)
  53.       screen()
  54.    end
  55. end
  56.  
  57. function decVol()
  58.    if currentVolume>0 then
  59.       currentVolume=currentVolume -1
  60.       play(currentSide,currentVolume)
  61.       screen()
  62.    end
  63. end
  64.  
  65. function screen()
  66. station(currentSide)
  67. m.setCursorPos(15,2)
  68. m.write("Stravides Radio Jukebox")
  69. m.setCursorPos(19,5)
  70. m.write("Volume: "..currentVolume.."  ")
  71. m.setCursorPos(20,16)
  72. m.write("You are listening to :")
  73. m.setCursorPos(20,17)
  74. m.write(currentStation)
  75. end
  76.  
  77. button.setMon("top")
  78.  
  79. button.add("radio1","Trance","flash",2,4,15,6,colors.red,colors.green,colors.white,function()  play("back",currentVolume) end)
  80. button.setState("radio1",false)
  81. button.add("radio2","Slay Radio","flash",2,8,15,10,colors.red,colors.green,colors.white, function() play("left",currentVolume) end)
  82. button.setState("radio2",false)
  83. button.add("radio3","Gamerz","flash",2,12,15,14,colors.red,colors.green,colors.white,function() play("right",currentVolume) end)
  84. button.setState("radio3",false)
  85. button.add("radio4","Capitol","flash",2,16,15,18,colors.red,colors.green,colors.white,function() play("bottom",currentVolume) end)
  86. button.setState("radio4",false)
  87.  
  88. button.add("incVol","+","flash",23,7,25,9,colors.red,colors.green,colors.white,function() addVol() end)
  89. button.add("decVol","-","flash",23,11,25,13,colors.red,colors.green,colors.white,function() decVol() end)
  90. button.draw()
  91.  
  92. screen()
  93. quietplease()
  94. while true do
  95.      button.check()
  96. end
Advertisement
Add Comment
Please, Sign In to add comment