Advertisement
Darking560

OpenRadio computer

Jan 30th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. modem = peripheral.wrap("left")
  2. m = peripheral.wrap("right")
  3. m.clear()
  4.  
  5. os.loadAPI("button")
  6.  
  7. local radio = {}
  8. local frequence = 0
  9. local volume = 1
  10. local nom = {
  11.   [1] = "off",
  12.   [2] = "Nova",
  13.   [3] = "Europe1",
  14.   [4] = "RTL2",
  15.   [5] = "Azenet"
  16. }
  17.  
  18. button.setTable("off",0,23,26,2,2)
  19. button.setTable("Nova",1,3,14,5,7)
  20. button.setTable("Europe1",2,16,27,5,7)
  21. button.setTable("RTL2",3,3,14,9,11)
  22. button.setTable("Azenet",4,16,27,9,11)
  23. button.setTable("<",10,2,2,15,15)
  24. button.setTable(">",11,28,28,15,15)
  25. button.toggleButton("off")
  26.  
  27. function execut(nb)
  28.     if nb == 0 then
  29.         volume = 1
  30.     end
  31.     if nb>=0 and nb <= 4 then
  32.         button.toggleButton(nom[frequence+1])
  33.         frequence = nb
  34.         button.toggleButton(nom[nb+1])
  35.     end
  36.     if nb == 10 and volume > 1 then
  37.         volume = volume-1
  38.     end
  39.     if nb == 11 and volume < 15 then
  40.         volume = volume+1
  41.     end
  42.     radio["fr"] = frequence
  43.     radio["vl"] = volume
  44.     modem.transmit(123,12,textutils.serialize(radio))
  45.     print(frequence..":"..volume)
  46. end
  47.  
  48. function ecran()
  49.     m.clear()
  50.     button.screen()
  51.     button.label(3,2,"OpenRadio")
  52.     button.label(10,13,"Volume")
  53.     button.label(12,17,volume.." V.")
  54.     button.label(13,19,"By Darking560")
  55.     local aff = math.floor((volume/15)*12)
  56.     m.setBackgroundColor(colors.gray)
  57.     for i=0,aff do
  58.         m.setCursorPos(4+(2*i),15)
  59.         m.write(" ")
  60.     end
  61.     m.setBackgroundColor(colors.black)
  62. end
  63.  
  64. while true do
  65.     ecran()
  66.     sleep(2)
  67.     event, side, x, y = os.pullEvent("monitor_touch")
  68.     local nb = button.checkxy(x,y)
  69.     execut(nb)
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement