My current project is a row of 8 relative rotary encoders passing MIDI to my DAW, I have been using the brilliant Control_Surface.h library by Pieter P.
All is working well, but I have come to need a variation in the optional multiplier control, and I don't understand how to implement the change required.
Rather than have a fixed multiplier rate, I wish to press a toggle button to choose between a fast rate, and a slow one. As some instances require more detail when using, but become cumbersome in general use.
The Arduino is currently the Uno using Hairless MIDI as the serial bridge.
The code below is a quick shortening of the actual code used, as it is the principle required that I'm most interested in.
Thanks in advance
#include <Encoder.h> // This must be done before the Control Surface library.
#include <Control_Surface.h> // Include the Control Surface library
HairlessMIDI_Interface midi;
const int encbut1 = 10; // button to trigger action
int encbutval = 5; // starting value
CCRotaryEncoder enc = {
{3, 2}, // pins
MCU:: V_POT_1, // MIDI address (CC number + optional channel)
encbutval, // this is the multiplier variable I would like to control
};
// Variables to debounce Rotary Encoder
long TimeOfLastDebounce = 0;
int DelayofDebounce = 0.01;
void setup() {
RelativeCCSender::setMode(relativeCCmode::TWOS_COMPLEMENT);
Control_Surface.begin();
Serial.begin(115200);
pinMode(encbut1, INPUT_PULLUP);
}
void loop() {
Control_Surface.loop(); // Update the Control Surface
// If enough time has passed check the rotary encoder
if ((millis() - TimeOfLastDebounce) > DelayofDebounce) {
TimeOfLastDebounce = millis(); // Set variable to current millis() timer
}
if (digitalRead(encbut1) == LOW) { // button press detection
encbutval = 1; //change of value
}
}