minor fix
This commit is contained in:
parent
05444a7548
commit
2d149b1090
3 changed files with 42 additions and 50 deletions
|
@ -52,6 +52,8 @@ void controlChange(byte channel, byte control, byte value) {
|
|||
MidiUSB.sendMIDI(event);
|
||||
}
|
||||
|
||||
// Constructor and methods for analog and buttons (encoders use a different library)
|
||||
|
||||
AnalogControl::AnalogControl(int pin, byte effect, int middle) {
|
||||
this->pin = pin;
|
||||
this->effect = effect;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "MIDIUSB.h"
|
||||
|
||||
// Uncomment this line if you want pin and values printed on the serial, remember to open a console because it waits until a connection is established.
|
||||
#define DEBUG
|
||||
//#define DEBUG
|
||||
|
||||
// Analog controls (sliders and potentiometers), the deadzone is the smallest increment that the control must have to trigger the effect.
|
||||
#define DEAD_ZONE 15
|
||||
|
|
|
@ -7,46 +7,22 @@
|
|||
*
|
||||
* This software is released under the Unlicense (see LICENSE for more info).
|
||||
*
|
||||
* Last revision 27-dec-2023
|
||||
* Last revision 14-mar-2024
|
||||
*/
|
||||
|
||||
// Pin definition
|
||||
// Analog knobs and sliders
|
||||
/* Connect linear potentiometers (sliders and knobs) to Analog Inputs on your board.
|
||||
* On Leonardo, from A0 to A5 are on the left (with USB on top)
|
||||
* A6, A7, A8, A9, A10 and A11 are digital pins:
|
||||
* 4, 6, 8, 9, 10, 12.
|
||||
* A6, A7, A8, A9, A10, A11 are digital pins:
|
||||
* 4, 6, 8, 9, 10, 12.
|
||||
*
|
||||
* Change the first value accordingly, the last one is the MIDI effect that is sent to
|
||||
* Mixxx, every control needs to have a unique number.
|
||||
*/
|
||||
|
||||
//Analog controls pins and effects (effects have to be unique among all controls)
|
||||
int analog_controls_pins[] = {A0,A1,A2,A3,A4,A5,A7,A10,A11};
|
||||
int analog_controls_effects[] = {7,8,9,1,2,3,4,5,6};
|
||||
|
||||
/* Rotary Encorders need two pins.
|
||||
* clk should be an interrupt. On Leonardo interrupts are on pin 0, 1, 2, 3 and 7.
|
||||
* dt are digital pins
|
||||
* rot_effect must be unique and also rot_effect+1 has to be
|
||||
* it's reserved for anticlockwise
|
||||
*/
|
||||
|
||||
const int rot_clk_pins[] = {2,3,0};
|
||||
const int rot_dt_pins[] = {4,5,1};
|
||||
const int rot_effect[] = {10,12,18};
|
||||
|
||||
/* Digital buttons are connected to a digital pin. If you use toggle, long press or long press toggle rembember that the MIDI message byte has to be unique.
|
||||
* long_inteval is the interval of long clicks, toggle and long_toggle (for long presses) send two different messages for odd and even strokes.
|
||||
* If effect is 0 the toggle, long press or long press toggle is disabled.
|
||||
*/
|
||||
|
||||
const int button_pins[] = {9,11,8,7,13};
|
||||
const int button_effect[] = {14,15,16,17,20};
|
||||
const int button_effect_toggle[] = {0,0,0,0,0};
|
||||
const int button_effect_long[] {0,23,0,24,25};
|
||||
const int button_effect_toggle_long[] {0,0,0,26,0};
|
||||
|
||||
|
||||
AnalogControl analog_controls[] = {
|
||||
AnalogControl(analog_controls_pins[0],analog_controls_effects[0],520),
|
||||
AnalogControl(analog_controls_pins[1],analog_controls_effects[1],520),
|
||||
|
@ -63,24 +39,35 @@ AnalogControl analog_controls[] = {
|
|||
|
||||
int active_analog_controls = sizeof(analog_controls)/sizeof(analog_controls[0]);
|
||||
|
||||
// Rotary encoders
|
||||
/* Rotary Encorders need two pins.
|
||||
* clk should be an interrupt. On Leonardo interrupts are on pin 0, 1, 2, 3 and 7.
|
||||
* dt are digital pins
|
||||
* rot_effect and rot_effect+1 must be unique
|
||||
* the +1 is reserved for anticlockwise
|
||||
*/
|
||||
|
||||
const int rot_clk_pins[] = {2,3,0};
|
||||
const int rot_dt_pins[] = {4,5,1};
|
||||
const int rot_effect[] = {10,12,18};
|
||||
EncoderButton rotary_encoders[] = {
|
||||
EncoderButton(rot_clk_pins[0],rot_dt_pins[0]),
|
||||
EncoderButton(rot_clk_pins[1],rot_dt_pins[1]),
|
||||
EncoderButton(rot_clk_pins[2],rot_dt_pins[2]),
|
||||
};
|
||||
|
||||
const int active_encoders = sizeof(rotary_encoders)/sizeof(rotary_encoders[1]);
|
||||
|
||||
void eb_Encoder(EncoderButton& eb) {
|
||||
int inc = eb.increment();
|
||||
if (inc > 0) {
|
||||
controlChange(1,eb.userId()+1,1);
|
||||
} else {
|
||||
controlChange(1,eb.userId(),1);
|
||||
}
|
||||
MidiUSB.flush();
|
||||
}
|
||||
// Digital buttons
|
||||
/* Digital buttons are connected to a digital pin. If you use toggle, long press or long press toggle rembember that the MIDI message byte has to be unique.
|
||||
* long_inteval is the interval of long clicks, toggle and long_toggle (for long presses) send two different messages for odd and even strokes.
|
||||
* If effect is 0 the toggle, long press or long press toggle is disabled.
|
||||
*/
|
||||
|
||||
const int button_pins[] = {9,11,8,7,13};
|
||||
const int button_effect[] = {14,15,16,17,20};
|
||||
const int button_effect_toggle[] = {0,0,0,0,0};
|
||||
const int button_effect_long[] {0,23,0,24,25};
|
||||
const int button_effect_toggle_long[] {0,0,0,26,0};
|
||||
|
||||
DigitalButton switches[] = {
|
||||
DigitalButton(button_pins[0],button_effect[0],button_effect_toggle[0],button_effect_long[0],button_effect_toggle_long[0]),
|
||||
|
@ -91,7 +78,16 @@ DigitalButton switches[] = {
|
|||
};
|
||||
const int active_switches = sizeof(switches)/sizeof(switches[0]);
|
||||
|
||||
|
||||
//Callback function for the encoders
|
||||
void eb_Encoder(EncoderButton& eb) {
|
||||
int inc = eb.increment();
|
||||
if (inc > 0) {
|
||||
controlChange(1,eb.userId()+1,1);
|
||||
} else {
|
||||
controlChange(1,eb.userId(),1);
|
||||
}
|
||||
MidiUSB.flush();
|
||||
}
|
||||
|
||||
void setup() {
|
||||
#ifdef DEBUG
|
||||
|
@ -101,30 +97,24 @@ void setup() {
|
|||
#endif
|
||||
|
||||
for (int i = 0; i < active_encoders; i++) {
|
||||
//pinMode(rot_clk_pins[i],INPUT);
|
||||
//pinMode(rot_dt_pins[i],INPUT);
|
||||
rotary_encoders[i].setUserId(rot_effect[i]);
|
||||
rotary_encoders[i].setEncoderHandler(eb_Encoder);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Analog controls check.
|
||||
// Analog controls check
|
||||
for (int i = 0; i < active_analog_controls; i++) {
|
||||
analog_controls[i].checkStatus();
|
||||
}
|
||||
|
||||
// Switches check.
|
||||
// Switches check
|
||||
for (int i = 0; i < active_switches; i++) {
|
||||
switches[i].checkStatus();
|
||||
}
|
||||
|
||||
// Rotary encoders check.
|
||||
// Rotary encoders check
|
||||
for (int i = 0; i < active_encoders; i++) {
|
||||
rotary_encoders[i].update();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue