Open zeysh opened 4 years ago
The problem is that you don't know when the button state changes. Basically, the code that loops is:
read input for selector
read input for note button
other stuff
repeat
If the state of the button changes between updating the selector and updating the note button, the note will be sent without changing the address.
The only solution is to write your own code that reads the input once, for both the selector and the button at the same time.
You'll have to do this anyway if you want to do more advanced button presses such as long presses etc.
You don't need to use a selector to change the bank, you can call bank.select(setting)
directly, see https://tttapa.github.io/Control-Surface-doc/Doxygen/db/dbd/classBank.html#a801ab5dedea8200f1cdb26533cb6f78b
Hi Pieter,
I hope you well.
I have a strange behavior with my code bellow.
I want to have a button, which on the first press PLAY my DAW and the second press STOP.
I reused a code(https://github.com/tttapa/Control-Surface/issues/220) you gave to me to toggle functions. It seems to work well, but sometimes, the bank doesn't switch.
I just declared the same PIN to change (
IncrementSelector
) the bank and the NoteButton (Bankable::ManyAddresses::NoteButton
). I guess that's why I got this glitch...include // Include the Control Surface library
USBMIDI_Interface midi;
// Create a Bank object to select one of two modes (PLAY, STOP) Bank<2> bank;
// Create a Selector object that reads a push button connected to pin 4 // to select which mode is active. IncrementSelector<2> pushbutton = {bank, 4};
Bankable::ManyAddresses::NoteButton<2> button = { bank, // bank selects active address 4, // push button pin {{ // addresses MCU::PLAY, MCU::STOP, }}, };
// --------------------------------- Setup ---------------------------------- //
void setup() { Serial.begin(115200); Control_Surface.begin(); // Initialize Control Surface }
// ---------------------------------- Loop ---------------------------------- //
void loop() { Control_Surface.loop(); // Refresh all elements static setting_t prevSetting = -1; setting_t setting = bank.getSelection(); if (setting != prevSetting) { const char *mode; switch (setting) { case 0: mode = "PLAY"; break; case 1: mode = "STOP"; break; default: mode = "";
}
Serial.println(mode);
prevSetting = setting;
}
}