Bankable buttons and rotary encoders using Control Surface library

Hello!
I have spent the morning pouring over documentation for the Control Surface library and have been struggling to understand how I should be implementing banks. My project is very simple and consists of 3 rotary encoders with built in buttons and a sliding switch with two positions. When the switch is toggled, the encoders should switch their functions. I tried basing my code off of this example, but I could not get it to work.

#include <Control_Surface.h>

USBMIDI_Interface midi;

Bank<2> bank(1);

SwitchSelector selector {bank, 18};

Bankable::CCButton() {
  {{bank, BankType::ChangeAddress}, 4, {MCU::MUTE_1, MCU::MUTE_2}},
};

void setup() {
  Control_Surface.begin();
}

void loop() {
  Control_Surface.loop();

For testing purposes I only had one button hooked up (pin 4), and also one side of the sliding switch (pin 18). Are banks the best way to achieve this, or should I be using something else?

Bankable MIDI output elements only have a single base address, so you cannot pass multiple addresses here. You can find the proper arguments in the Bankable::CCButton constructor documentation.
You need to instantiate a global variable of type Bankable::CCButton, the CCButton() { ... }; syntax you used is not valid C++.

A valid example would be:

Bankable::CCButton my_button {
  {{bank, BankType::ChangeAddress}, 4, {MCU::MUTE_1}},
};

The effective address of a bankable MIDI output element is the base address (i.e. the address passed to the CCButton constructor in the example above) plus an offset that depends on the "selector" (one if the selector switch is on, zero if it's off) and the tracksPerBank property of the bank (which you set to one in the code above). You can find more information in the “How do banks work?” section in the FAQ: Control Surface: Frequently Asked Questions

Specifically, the address of the messages sent by the CCButton above would be: MCU::MUTE_1 + 1 × 0 if the switch is off, and MCU::MUTE_1 + 1 × 1 if the switch is on. If your use case does not fit the linear relationship b + a x, then you can use the ManyAddresses bankable MIDI elements, which support individual addresses for each each bank rather than just a base address b and a bank offset factor a.

For MIDI output elements with state (e.g. CCButton or CCAbsoluteEncoder), banks are the right approach to change their MIDI addresses at run time.
If you're using a MIDI output element without any state (e.g. CCRotaryEncoder), you don't have to use banks, you could also use the setAddress() function to manually change the MIDI address: Control Surface: CCRotaryEncoder Class Reference

Deleted the last post because I ended up figuring out the issue, for some reason when I had the slider switch attached to an analog pin, it would not cooperate. As soon as I switched it to a digital pin, everything worked as expected! Thank you so much for your help!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.