Bankable CCButtons with Latched Increment Selector Switch #397
Unanswered
tmanning47
asked this question in
Q&A
Replies: 2 comments 7 replies
-
Start by trying the Button example for pin A0. If that doesn't work, there's something wrong with the wiring of your switch. I'll see if I can add a selector for latched switches. |
Beta Was this translation helpful? Give feedback.
7 replies
-
15 buttons, 1 potentiometer for bank control; buttons send Midi CC + Joystick button commands simultaneously. Keeping my code updated here, having this this backed up has saved my bacon a few times now: #include <Encoder.h>
#include <Control_Surface.h> // Include the Control Surface library
BEGIN_CS_NAMESPACE
namespace Bankable {
template <class BankAddress, class Sender, uint8_t NumButtons>
class MIDIButtons1 : public MIDIOutputElement {
protected:
MIDIButtons1(BankAddress bankAddress,
const Array<AH::Button, NumButtons> &buttons,
const RelativeMIDIAddress &incrementAddress,
const Sender &sender)
: address(bankAddress), buttons{buttons},
incrementAddress(incrementAddress), sender{sender} {}
public:
void begin() final override {
for (auto &button : buttons)
button.begin();
}
void update() final override {
RelativeMIDIAddress offset = {0, 0, 0};
for (auto &button : buttons) {
AH::Button::State state = button.update();
if (state == AH::Button::Falling) {
//if (!activeButtons)
//address.lock(); // Don't allow changing of the bank setting
MIDIAddress sendAddress = address.getActiveAddress() + offset;
sender.sendOn(sendAddress);
activeButtons++;
} else if (state == AH::Button::Rising) {
MIDIAddress sendAddress = address.getActiveAddress() + offset;
sender.sendOff(sendAddress);
activeButtons--;
//if (!activeButtons)
//address.unlock();
}
offset += incrementAddress;
}
}
#ifdef AH_INDIVIDUAL_BUTTON_INVERT
void invert() {
for (auto &button : buttons)
button.invert();
}
#endif
AH::Button::State getButtonState(size_t index) const {
return buttons[index].getState();
}
private:
BankAddress address;
Array<AH::Button, NumButtons> buttons;
RelativeMIDIAddress incrementAddress;
uint8_t activeButtons = 0;
public:
Sender sender;
};
} // namespace Bankable
END_CS_NAMESPACE
BEGIN_CS_NAMESPACE
namespace Bankable {
template <uint8_t NumButtons>
class CCButtons1
: public MIDIButtons1<SingleAddress, DigitalCCSender, NumButtons> {
public:
CCButtons1(OutputBankConfig<> config,
const Array<AH::Button, NumButtons> &buttons,
MIDIAddress baseAddress, RelativeMIDIAddress incrementAddress,
const DigitalCCSender &sender = {})
: MIDIButtons1<SingleAddress, DigitalCCSender, NumButtons>(
{config, baseAddress}, buttons, incrementAddress, sender) {}
};
} // namespace Bankable
END_CS_NAMESPACE
#include <AH/Hardware/Button.hpp>
USBMIDI_Interface midi; //-----COMMENT OUT IF DEBUGGING-----
//USBDebugMIDI_Interface midi = 115200; //Uncomment to Debug -- 115200 baud -- DEBUG
Bank<6> bank1(1,0);
// │ └───── number of tracks per bank , starting bank
// └───────────── number of banks
//using namespace MIDI_Notes;
Bankable::CCButtons1<15> buttons = {
{bank1, BankType::CHANGE_CHANNEL},
{0,1,2,3,4,5,6,7,8,9,10,11,12,13,A0}, // button pins
{MIDI_CC::General_Purpose_Controller_1, CHANNEL_1}, // address of first button
{1, 0}, // interval between addresses (1 controller number, 0 channels , cable)
{0x7F, 0x7F}, //Sends ON Message Only {0x7F, 0x7F} Sends On Off {0x7F, 0x00}
};
//CCButton button15 (A0, {MIDI_CC::General_Purpose_Controller_1, CHANNEL_4},{0x7F, 0x7F});
//Button button15 {A0}; // Button to test if changing the address in the loop() works
// CC Values 1=16 2=17 3=18 4=19 5=20 6=21 7=22 8=23 9=24 10=25 11=26 12=27 13=28 14=29 15=30
// Pins 0 1 2 3 4 5 6 7 8 9 10 11 12 13 A0
int potentiometer_pin = A5;
int potentiometer_value = 0;
int pulse_value = 0;
void setup() {
Control_Surface.begin(); // Initialize Control Surface
}
void loop() {
Control_Surface.loop(); // Update the Control Surface
potentiometer_value = analogRead(potentiometer_pin);
pulse_value = potentiometer_value / 250;
//bank1.select(pulse_value);
//Serial.println(pulse_value);
//delay(1000);
switch(pulse_value) {
case 4:
//Serial.println("Bank 1");
bank1.select(0);
break;
case 3:
//Serial.println("Bank 2");
bank1.select(1);
break;
case 2:
//Serial.println("Bank 3");
bank1.select(2);
break;
case 1:
//Serial.println("Bank 4");
bank1.select(3);
break;
case 0:
//Serial.println("Bank 5");
bank1.select(4);
break;
default:
//Serial.println("Default");
break;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been working on a guitar pedalboard using 15 latching footswitches, and I'm a bit stumped as to getting bank switching to work. A0 is the pin for the bank switch
I also have a feeling that CCbuttons may not be the best class to use.
I saw a similar question in regards to latched increment selectors on the discussion board but decided I didn't want to piggyback off that thead.
Any help with this is greatly appreciated!
Current Code: (CCButtons work, bank increment button does nothing)
Beta Was this translation helpful? Give feedback.
All reactions