I have this setup on a BU16 but you can use the following code on the buttons on your PBF4. On the ‘System’ element ‘Setup’ tab, delete the current contents and add the following to a ‘Code’ block:
active = nil
last = 9
function init_element(i)
if i <= 9 then
element[i]:button_value(2)
event_trigger(i, 3)
else
end
end
I don’t use ‘Utility’, ‘Midi rx’, or ‘Timer’ on the ‘System’ element so I generally delete all code on those tabs.
On each of the button elements ‘Setup’ tab, delete all code blocks, add in a ‘Code’ block, then overwrite any of the default code with the following:
local red, gre, blu = led_default_red(), led_default_green(), led_default_blue()
self.cc, self.ch, self.ei = (module_position_x() + 1) + self:element_index(), 0, self:element_index()
led_color(self.ei, 1, red, gre, blu, 1)
You can change the variable assignments for ‘red’, ‘gre’, and ‘blu’ to the actual RGB values you want to use by replacing their assignments to actual RGB values instead of the ‘led_default_red()’ etc. functions. I use the following tool when doing this:
RGB Color Picker
The same can be done for the MIDI CC and channel. Replace the formulae with the CC and channel you want to use for that button.
On the ‘Button’ tab, delete all of the action blocks, add in a ‘Code’ block, then overwrite any of the default code with the following:
local bv, bs = self:button_value(), self:button_state()
if bv == 2 and active ~= self.ei then
element[last]:button_value(0)
midi_send(self.ch, 176, self.cc, 0)
led_value(self.ei, 1, 0)
elseif bs == 127 and bv == 127 and self.ei ~= last then
midi_send(self.ch, 176, self.cc, 127)
led_value(self.ei, 1, 80)
init_element(last)
last = self.ei
elseif bs == 0 then
end
I’m not using the ‘Timer’ so I delete the code block on that tab.
The way this code works is, when you press a button, it sends the assigned CC with a value of 127, sets itself to active and flags itself as the last button to have activated. If you press the same button again, nothing happens. When you press another button, it sends its assigned CC with a value of 127, assigns it self as active, calls a function to have the last button used sends its CC with a value of 0 then sets itself to last.
I setup my code so that all button LEDs are off unless active. It’s super easy to easy to see what it and what isn’t active. If you want all buttons to be lit at all times while the active button flashes, it’s easy enough to do but it’s more code to add.
Cheers!