How to change all the leds on en16 with immediate_send?

Hi!
I have a Bu16 that has one button that changes the led color of the first pot on a ENC16 with:

immediate_send(-1,0,‘led_color(0, 1, 105, 255, 8)’)

How can I do the same for the whole ENC16 module pot leds?

I cant figure this out,

Cheers

1 Like

Are you wanting to set all LEDs to the same color/value at the same time?

Use a ‘for’ loop to call ‘immediate_send()’ for as many elements as there are in the EN16 module.

1 Like

To limit the amount of serial communication required between modules, I suggest you avoid calling immediate_send() in a for loop.

Instead, define a global function called update_leds in the EN16 module Setup. It can take the same arguments as led_color, and update each LED in a for loop. That way you only need to call immediate_send(-1, 0, 'update_leds(0, 1, 105, 255, 8)') once.

1 Like

hi!
i don’t understand why my code does’nt work…
a sugestion please?

for i = 0,15 do
immediate_send(0, -1, ‘led_color(i, 1, 255, 255, 255)’)
end

Your “i” is interpreted as part of the string here, so the other module is trying to make sense of it and is failing to do so.

Proper syntax would be:

immediate_send(0, -1, "led_color("..i..", 1, 255, 255, 255)")

This is how you put a variable into the string dynamically in LUA. Hope this helps!

ho yes!
it wors very fine.
thank you very much