Open basichumantastes opened 3 years ago
This is not as trivial as it might seem. Because encoders use interrupts, you cannot have multiple instances on the same pins. You'll have to use the borrowed encoder classes that store a reference to the Encoder object, not just a copy of the Encoder itself.
Next, when you enable one encoder and disable the other one, you have to update the MIDI element's encoder offset and remainder: https://tttapa.github.io/Control-Surface-doc/new-input/Doxygen/db/d50/Abstract_2MIDIRotaryEncoder_8hpp_source.html#l00075
Otherwise, the enabled encoder will jump to the position of the one that you just disabled.
There is currently no standard way to do this, so you'll have to add some getters and setters to the GenericMIDIRotaryEncoder class. I think overwriting the deltaOffset
and remainder
of the encoder to be enabled by the ones from the encoder to be disabled should work.
thanks a lot for those informations ! Let's get back to work :)
I managed to use the borrowed class for the first CC control of the encoder . I had to switch to the new input branch to get that workin and it did (at least for the non banked one).
I edited a simplified version of my code to work on this feature because my board crashes each time I click the EncoderClick Button to toggle the state of the encoder, and it still does .
Any idea on what I am doing wrong ? here is the simplified code :
thanks for your time !
#include <Arduino_Helpers.h>
#include <Control_Surface.h>
USBMIDI_Interface midi;
using namespace ExtIO;
using namespace MIDI_Notes;
//////////////////////////////////MULTIPLEXER/////////////////////////////////
//CREATE MUX
CD74HC4067 mux = {
4, // Common Digital pin
{5, 6, 7, 8} // Address pins S0, S1, S2, S3
};
//DECLARE MUXBUTTONS
const pin_t RotarySW = mux.pin(0);
Button EncoderClick = (RotarySW);
////////////////////////////////////////ENCODER//////////////////
// DECLARE PHYSICAL ENCODER
Encoder enc (2, 3);
//DECLARE VIRTUAL ENCODER FROM PHYSICAL
//enc - used as track selector
BorrowedCCRotaryEncoder TrackSelectenc = {
enc,
{MIDIAddress(20, CHANNEL_1)},
1,
};
//Volumeenc - used as Volume Control
BorrowedCCRotaryEncoder Volumeenc = {
enc,
{MIDIAddress(21, CHANNEL_1)},
1,
};
///////////////VARIABLES/////////
bool toggle = 1;
void setup()
{
Control_Surface.begin();
EncoderClick.begin();
RelativeCCSender::setMode(relativeCCmode::TWOS_COMPLEMENT);
}
void loop() {
Control_Surface.loop();
//EncoderClick.invert();
if (EncoderClick.update()==Button::Falling){
toggle = !toggle;
if (toggle) {
BorrowedCCRotaryEncoder::enable(Volumeenc);
BorrowedCCRotaryEncoder::disable(TrackSelectenc);
} else {
BorrowedCCRotaryEncoder::enable(TrackSelectenc);
BorrowedCCRotaryEncoder::disable(Volumeenc);
}
digitalWrite (27, toggle); //LED FEEDBACK toggle state
};
};
I think the problem could be that both encoders start off enabled, so when you press the button, you try to enable an encoder that was enabled already. Try disabling one of the encoders in your setup.
If you define DEBUG_OUT
as Serial
, it'll print the error to the Serial port.
You shouldn't include Arduino_Helpers.h
, Control_Surface.h
should be sufficient.
Hello there ! First of all , thanks a lot for this amazing library , without which , as a non programmer, I would not be able to enter this world of creation .
The project i'm workin on is a Midi controller with one rotary encoder and some buttons to select what the encoder is doing .
I successfully used Bankable::CCRotaryEncoder with a ManyButtonsSelectorLEDS to switch between the encoder's functions , changing the MIDIAddress .
What I would like to do now and which is giving me a headache for 1 week, is that :
-6 buttons in a ManyButtonsSelectorLEDs to select the MIDI Address of the rotary encoder from CC21 to CC26 -1 button (RotarySW) witch toggles between MIDI CC20 and the last ManyButtonsSelectorLEDs.
Thanks for helping !