Change led colors from an external midi message

Lunchtime so I can look into this and I think I see the issue now…checking.

Bingo! Got i!

midirx_enabled(1)
rgb = {
    {255, 0, 0},
    {125, 50, 0},
    {100, 100, 100},
    {200, 200, 200},
    {0, 0, 0},
    {0, 255, 0},
    {255, 255, 255},
    {50, 50, 250}
}
function set_color(cl)
    for i = 0, 8, 1 do
        led_color(i, 2, rgb[cl][1], rgb[cl][2], rgb[cl][3])
        led_value(i, 2, 50)
    end
end

The functions led_color() and led_value() do not need to be called with element[i] as they already take parameters to indicate which element to address. Also, I needed to call led_value() so that the new color settings apply.

Tested on mine as working.

Full proper code:

-- 'Init tab'

midirx_enabled(1)
rgb = {
    {255, 0, 0},
    {125, 50, 0},
    {100, 100, 100},
    {200, 200, 200},
    {0, 0, 0},
    {0, 255, 0},
    {255, 255, 255},
    {50, 50, 250}
}
function set_color(cl)
    for i = 0, 7, 1 do
        led_color(i, 2, rgb[cl][1], rgb[cl][2], rgb[cl][3])
        led_value(i, 2, 50)
    end
end

-- 'MIDI rx' tab

local ch, cmd, param1, param2 = midi.ch, midi.cmd, midi.p1, midi.p2

if cmd == 176 and ch == 0 and param1 == 4 then
    set_color(param2)
else
end

To add to this, delete all blocks in both ‘Init’ and ‘MIDI rx’ on the ‘System’ element. Create a new ‘Code’ block in each and copy the appropriate snippets of code.

:clap: :clap: :clap: uooooo, it’s working!!!
just need to change the 8 to 7
“or i = 0, 7, 1 do” maybe it counts from 0
going to program the real colors and will share a video changing them from the monome
lot of thanks one more time!!

1 Like

Nope. Correct! We first initialize and assign ‘0’ to ‘i’ as that is the first element index. Then, we repeat the loop ‘8’ times incrementing by ‘1’. You are correct. We set it to ‘7’ as we are counting to ‘7’ not iterating that many times.

That will set the LEDs on the first 8 elements of the PO16.

Also led_value(i, 2, 50) will set the intensity of the LED. I used ‘50’ as it’s not super crazy bright. I believe the values here go from 0-255. You’ll want to reference the docs on it though to see the full behavior:

You can also do this from a max for live device - doesn’t have to be a remote script.

1 Like

Nice. Good to know! :slight_smile:

1 Like