ZeeDerp

LampControlStrobeOnly

Jun 14th, 2021 (edited)
1,929
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mount = function (peripheral_type)
  2.     for _,location in pairs(peripheral.getNames()) do
  3.         if peripheral.getType(location) == peripheral_type then
  4.             return peripheral.wrap(location)
  5.         end
  6.     end
  7.     return false
  8. end
  9.  
  10. lamp = mount("modem")
  11. hue = 0.00
  12.  
  13. function toHex(dec)
  14.     return(string.format("%x",dec))
  15.  end
  16.  
  17. function toDec(hex)
  18.     return(tonumber(hex))
  19. end
  20. function hsvToRgb(h, s, v)
  21.     local r, g, b
  22.     local i = math.floor(h * 6);
  23.     local f = h * 6 - i;
  24.     local p = v * (1 - s);
  25.     local q = v * (1 - f * s);
  26.     local t = v * (1 - (1 - f) * s);
  27.     i = i % 6
  28.     if i == 0 then r, g, b = v, t, p
  29.     elseif i == 1 then r, g, b = q, v, p
  30.     elseif i == 2 then r, g, b = p, v, t
  31.     elseif i == 3 then r, g, b = p, q, v
  32.     elseif i == 4 then r, g, b = t, p, v
  33.     elseif i == 5 then r, g, b = v, p, q
  34.     end
  35.     rHex = toHex(math.floor(r*255))
  36.     gHex = toHex(math.floor(g*255))
  37.     bHex = toHex(math.floor(b*255))
  38.     if string.len(rHex) <= 1 then
  39.        rHex = rHex..0
  40.     end
  41.     if string.len(gHex) <= 1 then
  42.        gHex = gHex..0
  43.     end
  44.     if string.len(bHex) <= 1 then
  45.        bHex = bHex..0
  46.     end
  47.     return("0x"..rHex..gHex..bHex)
  48. end
  49. function centerText(text)
  50.     local x,y = term.getSize()
  51.     term.setCursorPos(math.floor((x / 2) - (text:len() / 2)), y)
  52.     write(text)
  53.     end
  54. while not stop do
  55.             for _,v in pairs(lamp.getNamesRemote()) do
  56.                 local hex = hsvToRgb(hue,1,1)
  57.                 local decimal = toDec(hex)
  58.                 lamp.callRemote(v,"setColor",decimal)
  59.             end
  60.             hue = hue+.01 -- Changing this to a smaller number will make the steps between colors smaller
  61.             sleep(.005) -- Changing this line to a bigger number will make the lamp stay one color longer
  62. end
  63.  
RAW Paste Data