# Multiple LED colours on one EN16 encoder

**URL:** <https://forum.intech.studio/t/multiple-led-colours-on-one-en16-encoder/127>\
**Category:** Grid\
**Created:** [March 10, 2024, 5:13am UTC](https://forum.intech.studio/t/multiple-led-colours-on-one-en16-encoder/127 "2024-03-10T05:13:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Superb\_Owl](https://forum.intech.studio/user_avatar/forum.intech.studio/superb_owl/32/58_2.png) [@Superb\_Owl](https://forum.intech.studio/u/Superb_Owl)\
**Post date:** [March 10, 2024, 5:13am UTC](https://forum.intech.studio/t/multiple-led-colours-on-one-en16-encoder/127/1 "2024-03-10T05:13:46Z")

</div>

Is it possible to use a spread of 16 colours on one EN16 encoder, ie cc output value 0-7 blue, 8-15 purple, 16-23 green etc?  
What would be the best way to approach this?

---

<div class="post-metadata">

**Author:** ![kertikristof](https://forum.intech.studio/user_avatar/forum.intech.studio/kertikristof/32/16_2.png) [@kertikristof](https://forum.intech.studio/u/kertikristof)\
**Post date:** [March 11, 2024, 2:26pm UTC](https://forum.intech.studio/t/multiple-led-colours-on-one-en16-encoder/127/2 "2024-03-11T14:26:34Z")

</div>

Hi!  
best approach now would be to hold the rgb colors in a global table and make a function which calls the right LED color. The current character limitation might be tricky to tackle, but here is some pseudo code to help you.

Global table for 16 colors:

```auto
clr = {{0,100,200},{200,50,10}, etc...}

```

The function:

```auto
function getClr(in)
local index = in // 16
-- i'm not sure if +1 is needed, but lua tables are referenced with 1 as starting index
return clr[index + 1] 
end

```

The above function and table can be put under system events. Then on a control element you can add a code block or put this in the Locals action block…

```auto
local c = getClr(self:encoder_value())

```

Add a Color action block (or call it by function) and use the R,G,B values of the getClr function.

```auto
led_color(self:element_index(), 2, c[1],c[2],c[3] )

```

The intensity should be set to 100 on layer 2 to make your changes visible.

---

<div class="post-metadata">

**Author:** ![Superb\_Owl](https://forum.intech.studio/user_avatar/forum.intech.studio/superb_owl/32/58_2.png) [@Superb\_Owl](https://forum.intech.studio/u/Superb_Owl)\
**Post date:** [March 11, 2024, 9:05pm UTC](https://forum.intech.studio/t/multiple-led-colours-on-one-en16-encoder/127/3 "2024-03-11T21:05:35Z")

</div>

Thanks 🙏  
Looks like I’m studying lua code today!

---

<div class="post-metadata">

**Author:** ![kertikristof](https://forum.intech.studio/user_avatar/forum.intech.studio/kertikristof/32/16_2.png) [@kertikristof](https://forum.intech.studio/u/kertikristof)\
**Post date:** [March 11, 2024, 9:19pm UTC](https://forum.intech.studio/t/multiple-led-colours-on-one-en16-encoder/127/4 "2024-03-11T21:19:25Z")

</div>

You’re welcome. Please respond to either of your threads if you get stuck! Happy exploring.

---

<div class="post-metadata">

**Author:** ![coti\_k](https://forum.intech.studio/letter_avatar_proxy/v4/letter/c/3da27b/32.png) [@coti\_k](https://forum.intech.studio/u/coti_k)\
**Post date:** [October 11, 2026, 1:37pm UTC](https://forum.intech.studio/t/multiple-led-colours-on-one-en16-encoder/127/5 "2026-10-11T13:37:18Z")

</div>

Hello **[kertikristof](https://forum.intech.studio/u/kertikristof)**,  
go my first EN16 a few days ago and have been trying to do the same thing, change led colors with incoing cc values.

I have suceeded to do it on an element, but as soon as i add the code to more they stop functioning.

i understand its most probaby a scope thing… but for the life of me i cannot see what i am doing wrong..

.

.

**here is my code in the setup tab:**

--the rgb table

self.clr = { { 0, 0, 0 }, { 0, 0, 64 }, { 0, 0, 255 }, { 0, 64, 64 }, { 0, 128, 128 }, { 0, 128, 64 }, { 0, 128, 0 }, { 0, 255, 0 }, { 64, 64, 0 }, { 128, 128, 0 }, { 100, 50, 0 }, { 200, 64, 0 }, { 100, 0, 0 }, { 255, 0, 0 }, { 128, 0, 128 } }

--the funciion that gets the rgb values and puts them in the respective parameters

function self.getSet(i)

local index = i

local c = self.clr[index]

print(i, c[1], c[2], c[3])

self.r = c[1]

self.g = c[2]

self.b = c[3]

end

.

.

**and the code in the encoder tab:**

self.cc = 2 --the cc number of the element

self.r, self.g, self.b = 255, 0, 155 --rgb init values

self.midirx\_cb = function(self, header, event)

local ch, msg, p1, p2 = event[1], event[2], event[3], event[4]

local g = self.getSet

if header[1] == 13 and ch == 0 and msg == 176 and p1 == self.cc then

if p2 == 0 then

```auto
  g(1)

```

elseif p2 \>= 1 and p2 \< 10 then

```auto
  g(2)

```

elseif p2 \>= 10 and p2 \< 20 then

```auto
  g(3)

```

elseif p2 \>= 20 and p2 \< 30 then

```auto
  g(4)

```

elseif p2 \>= 30 and p2 \< 40 then

```auto
  g(5)

```

elseif p2 \>= 40 and p2 \< 50 then

```auto
  g(6)

```

elseif p2 \>= 50 and p2 \< 60 then

```auto
  g(7)

```

elseif p2 \>= 60 and p2 \< 70 then

```auto
  g(8)

```

elseif p2 \>= 70 and p2 \< 80 then

```auto
  g(9)

```

elseif p2 \>= 80 and p2 \< 90 then

```auto
  g(10)

```

elseif p2 \>= 90 and p2 \< 100 then

```auto
  g(11)

```

elseif p2 \>= 100 and p2 \< 110 then

```auto
  g(12)

```

elseif p2 \>= 110 and p2 \< 120 then

```auto
  g(13)

```

elseif p2 \>= 120 and p2 \< 127 then

```auto
  g(14)

```

elseif p2 == 127 then

```auto
  g(15)

```

end

self:led\_color(-1, { { self.r, self.g, self.b, 0.5 } })

self:led\_value(-1, 255)

end

end

.

.

please help!! thanks
