Multiple LED colours on one EN16 encoder

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?

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:

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

The function:

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…

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.

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.

Thanks :pray:
Looks like I’m studying lua code today!

1 Like

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

Hello 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

  g(1)

elseif p2 >= 1 and p2 < 10 then

  g(2)

elseif p2 >= 10 and p2 < 20 then

  g(3)

elseif p2 >= 20 and p2 < 30 then

  g(4)

elseif p2 >= 30 and p2 < 40 then

  g(5)

elseif p2 >= 40 and p2 < 50 then

  g(6)

elseif p2 >= 50 and p2 < 60 then

  g(7)

elseif p2 >= 60 and p2 < 70 then

  g(8)

elseif p2 >= 70 and p2 < 80 then

  g(9)

elseif p2 >= 80 and p2 < 90 then

  g(10)

elseif p2 >= 90 and p2 < 100 then

  g(11)

elseif p2 >= 100 and p2 < 110 then

  g(12)

elseif p2 >= 110 and p2 < 120 then

  g(13)

elseif p2 >= 120 and p2 < 127 then

  g(14)

elseif p2 == 127 then

  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