Button action to toggle LEDs off on EN16 | Intech Studio
💬 general GridRequest

Button action to toggle LEDs off on EN16

Martin Grider
Martin Grider · · 10 replies

I would like to program one of the buttons on my EN16 to just toggle all the LEDs on the unit off. This is because I keep it plugged into my computer all the time, and at night it's a subtle glow in the corner of my bedroom. Is there an easy/built-in way to do this? Would someone be willing to help me with the LUA if not?

Replies (10)

Martin Grider Martin Grider ·

I created some lua code that looks like this:

leds_are_on = true
function leds_off()
    for i = 0, 15 do
        led_value(i, 1, 0)
    end
    leds_are_on = false
end
function leds_on()
    for i = 0, 15 do
        led_value(i, 1, 255)
    end
    leds_are_on = true
end
function leds_toggle()
    if leds_are_on == true then
        leds_off()
    else
        leds_on()
    end
end
Martin Grider Martin Grider ·

I put it in the system event init, and call leds_toggle() in my button press.

Martin Grider Martin Grider ·

I celebrated too early here. This doesn't seem to work. After leds_off() is called, the LEDs are quite dim, but still definitely visible. Is there a way to turn them off entirely? I'm going to try setting their color to {0,0,0} next.

Hybrid Hybrid ·

Hi @user, I think the setting you're missing to make the LEDs turn off completely is the Beautify toggle – this needs to be turned off to allow the LEDs to go completely dark. See the documentation page and also my screenshot attached with the relevant sections highlighted.

Since there are 2 layers in use for the encoder elements, in your code you might have to set the led_value intensity to 0 on both layers. Something like this:

led_value(i, 1, 0)
led_value(i, 2, 0)

Hopefully you'll be able to get it working with that. If you want more info, there's a long thread here where I tried to help someone else with the LED configuration.

According to the latest update from Intech via Kickstarter, the LED settings in the Editor will soon be getting an overhaul and that should also make it easier to do this kind of thing.

image.png
Martin Grider Martin Grider ·

Alright, here's where I ended up. Works great!

leds_are_on = true
function leds_off()
    for i = 0, 15 do
        led_color(i, 1, 0, 0, 0, 0)
        led_color(i, 2, 0, 0, 0, 0)
    end
    leds_are_on = false
end
function leds_on()
    for i = 0, 15 do
        led_color(i, 1, led_default_red(), led_default_green(), led_default_blue(), 0)
        led_color(i, 2, led_default_red(), led_default_green(), led_default_blue(), 0)
    end
    leds_are_on = true
end
function leds_toggle()
    if leds_are_on == true then
        print("turning leds off...")
        leds_off()
    else
        print("turning leds on...")
        leds_on()
    end
end
Martin Grider Martin Grider ·

It took some digging, but this page has documentation for the led_color and led_value functions: https://docs.intech.studio/reference-manual/grid-functions/led

Hybrid Hybrid ·

Nice one, glad you got it working! 🎉

Thanks for sharing your code – I'm interested to see that you only used the led_color function in the end. Maybe I'm not understanding it fully due to not being able to test any code yet but my preference would have been to avoid changing the colours – instead, just set the intensity. Obviously, in order to have the LED turn off completely, you need to have the Beautify parameter set to off (which seems to be a value of 1, oddly). However I think you could have it toggled off on all the LEDs when they are initialised. The reason I'm thinking about this is for situations where the LEDs are different colours: unless the led_default_* functions return the initially set RGB values for each individual LED, it seems to me that you'd lose any unique set colours on the grid. Does that make sense? It's something I'll have to test once I get my modules 😀

Martin Grider Martin Grider ·

It didn’t even occur to me to change the “beautify” setting in the editor. The led_color function was the only way I saw to set it in code. 😂

Martin Grider Martin Grider ·

And yes, my understanding is that the default functions get the colors from initialization. But maybe just for the “page”? Documentation for the red one says:

This function returns the red RGB LED value default for the page when called.

Hybrid Hybrid ·

I'm still waiting to receive my modules, so all my understanding is theoretical at this point... 😅 However, I read that same part of the manual that you quoted and I understood it to be for the whole page, not the individual element. We'd need to test it to know for sure.

Everything you see in the Editor is just a GUI that gets translated into code. For example, see the attached screenshots for the default setup of an encoder element – all I did was toggle the beautify switches. You can then use the "merge action(s) to code" button to generate the code shown in the second screenshot. From my understanding, this code is run automatically when initialising the Grid, so it makes sense to leverage that.

image.pngimage.png
Discord

View on Discord

This post is from the Intech Studio Discord community.

Open thread →