Advertisement
Guest User

lampServer

a guest
Nov 27th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. colorTable = {}
  2.  
  3. term.clear()
  4. term.setCursorPos(1,1)
  5. term.setTextColor(colors.lime)
  6. print("Opening rednet on side top")
  7. rednet.open("top")
  8.  
  9. function colorToHex(rgb)
  10.   local hexadecimal = ''
  11.        for key, value in pairs(rgb) do
  12.             local hex = ''
  13.             while(value > 0)do
  14.                  local index = math.fmod(value, 16) + 1
  15.                  value = math.floor(value / 16)
  16.                  hex = string.sub('0123456789ABCDEF', index, index) .. hex         
  17.             end
  18.             if(string.len(hex) == 0)then
  19.                  hex = '00'
  20.          elseif(string.len(hex) == 1)then
  21.                  hex = '0' .. hex
  22.             end
  23.             hexadecimal = hexadecimal .. hex
  24.       end
  25.       return hexadecimal
  26. end
  27.  
  28. function sendColor(hex)
  29.   rednet.broadcast(hex,"Lamp")
  30. end
  31.  
  32. while true do
  33.   red = 3
  34.   green = 3
  35.   blue = 3
  36.  
  37.   colorTable["r"] = red
  38.   colorTable["g"] = green
  39.   colorTable["b"] = blue
  40.  
  41.   hex = colorToHex(colorTable)
  42.   sendColor(hex)
  43.   sleep(0)
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement