Noob trouble - CCButton with a MUX and rising edge triggering #1000
-
Hello everyone. I'm Jake, and I'm an enthusiastic noob begging for help 🙏 I am making some midi peripherals which connects to some sampling software (GrandOrgue, for those who are interested). I managed to build some working code which allows MIDI communications between my hardware (LED illuminated pushbuttons) and the GrandOrgue software, however, I'm now experimenting with some capacitive touch buttons (TTP223) which requires a modified code. My limited understanding of Arduino's coding language and structure has stopped me in my tracks, so I come here, cap-in-hand, to ask for some help. System ExplanationMy code uses Control_Surface and USBMIDI_Interface on a SparkFun Pro Micro (ATMega32u4 which supports MIDI over USB). I have 13 momentary push buttons (close to ground) feeding in a CD74HC4067 mux. The button's LEDs are fed directly from the Pro Micro pins. When a button shorts to ground a MIDI_NOTES is sent (below):
The CCButton command (?) expects a falling edge trigger, which is fine for my pushbuttons, however the capacitive touch button (TTP223) provides a rising edge. I can't seem to use the CCButton for this application, so I swapped to a pushbutton variable changing over the pushbutton.update;
if (pushbutton.getState() == Button::Rising)
midi.sendNoteOn({MIDI_Notes::C(4), CHANNEL_1}, velocity);
else if (pushbutton.getState() == Button::Falling)
midi.sendNoteOff({MIDI_Notes::C(4), CHANNEL_1}, velocity); This works for my TTP223 capacitive touch button, but I'm now lost on how to integrate a MUX with it. Having looked in to the Control_Surface library I can't find a similar The NoteLED command receives a MIDI message (MIDI_NOTES) and illuminates the corresponding pushbutton's LED. This continues to work just fine, so I haven't touched it. My CodeI'm an electrical engineer with very limited coding experience, so I post this here openly and honestly 😬. I know it is a confused mix of code, but it was cobbled together from sources who kindly made their code available. The below works for falling-edge push buttons, but not for a rising-edge. It complies and runs just fine for me on my Pro Micro. I have a slightly modified version running on an older Leonardo. // Working mod as of 30/09/2023
// JS Allinson CEng BEng
// Designed as MIDI interface to GrandOrgue open source virtual pipe organ (VPO) software - https://github.com/GrandOrgue/grandorgue
// Include the library
#include <Control_Surface.h>
// Instantiate a MIDI Interface to use
USBMIDI_Interface midi;
// Instantiate an analog multiplexer
CD74HC4067 mux {
A0, // Analog input pin
{2, 3, 4, 5} // Address pins S0, S1, S2
};
#define LED_PIN0 1 // Gen0LED
#define LED_PIN1 0 // Gen1LED
#define LED_PIN6 6 // Gen2LED
#define LED_PIN7 7 // Gen3LED
#define LED_PIN8 8 // Gen4LED
#define LED_PIN9 9 // Gen5LED
#define LED_PIN10 10 // Gen6LED
#define LED_PIN14 14 // Gen7LED
#define LED_PIN15 15 // Gen8LED
#define LED_PIN16 16 // SPARE
NoteLED led0 {
LED_PIN0, // Pin of built-in LED
{MIDI_Notes::C(4), CHANNEL_1}, // Note C4 on MIDI channel 1
};
NoteLED led1 {
LED_PIN1,
{MIDI_Notes::D(4), CHANNEL_1}, // Note D4 on MIDI channel 1
};
NoteLED led6 {
LED_PIN6,
{MIDI_Notes::E(4), CHANNEL_1}, // Note E4 on MIDI channel 1
};
NoteLED led7 {
LED_PIN7,
{MIDI_Notes::Gb(4), CHANNEL_1}, // Note F#4 on MIDI channel 1
};
NoteLED led8 {
LED_PIN8,
{MIDI_Notes::Ab(4), CHANNEL_1}, // Note G#4 on MIDI channel 1
};
NoteLED led9 {
LED_PIN9,
{MIDI_Notes::Bb(4), CHANNEL_1}, // Note A#4 on MIDI channel 1
};
NoteLED led10 {
LED_PIN10,
{MIDI_Notes::C(5), CHANNEL_1}, // Note C5 on MIDI channel 1
};
NoteLED led14 {
LED_PIN14,
{MIDI_Notes::D(5), CHANNEL_1}, // Note D5 on MIDI channel 1
};
NoteLED led15 {
LED_PIN15,
{MIDI_Notes::E(5), CHANNEL_1}, // Note E5 on MIDI channel 1
};
NoteLED led16 {
LED_PIN16,
{MIDI_Notes::Gb(5), CHANNEL_1}, // Note F#5 on MIDI channel 1
};
// Create an array of potentiometers that send out
// MIDI Control Change messages when you turn the
// potentiometers connected to the eight input pins of
// the multiplexer
CCButton button[] {
{mux.pin(0), {MIDI_Notes::C(4), CHANNEL_1}}, // GEN0
{mux.pin(1), {MIDI_Notes::D(4), CHANNEL_1}}, // GEN1
{mux.pin(2), {MIDI_Notes::E(4), CHANNEL_1}}, // GEN2
{mux.pin(3), {MIDI_Notes::Gb(4), CHANNEL_1}}, // GEN3
{mux.pin(4), {MIDI_Notes::Ab(4), CHANNEL_1}}, // GEN4
{mux.pin(5), {MIDI_Notes::Bb(4), CHANNEL_1}}, // GEN5
{mux.pin(6), {MIDI_Notes::C(5), CHANNEL_1}}, // GEN6
{mux.pin(7), {MIDI_Notes::D(5), CHANNEL_1}}, // GEN7
{mux.pin(8), {MIDI_Notes::E(5), CHANNEL_1}}, // GEN8
{mux.pin(9), {MIDI_Notes::Gb(5), CHANNEL_1}}, // FWD
{mux.pin(10), {MIDI_Notes::Ab(5), CHANNEL_1}}, // BCK
{mux.pin(11), {MIDI_Notes::Bb(5), CHANNEL_1}}, // SET
{mux.pin(12), {MIDI_Notes::C(6), CHANNEL_1}}, // G.C.
};
// Initialize the Control Surface
void setup() {
Control_Surface.begin();
midi.begin();
pinMode (LED_PIN0, OUTPUT); // GEN0
pinMode (LED_PIN1, OUTPUT); // GEN1
pinMode (LED_PIN6, OUTPUT); // GEN2
pinMode (LED_PIN7, OUTPUT); // GEN3
pinMode (LED_PIN8, OUTPUT); // GEN4
pinMode (LED_PIN9, OUTPUT); // GEN5
pinMode (LED_PIN10, OUTPUT); // GEN6
pinMode (LED_PIN14, OUTPUT); // GEN7
pinMode (LED_PIN15, OUTPUT); // GEN8
pinMode (LED_PIN16, OUTPUT); // SPARE
}
// Update the Control Surface
void loop() {
Control_Surface.loop();
midi.update();
} MeI'm Jacob, a Chartered Electrical Engineer with a degree in Electronic and Electrical Engineering, so this feels like one of those tasks I should be able to do. Given the very technical nature of my day-to-day job (building power stations) I'm frustrated at not being able to figure this out. Someone's help and patience would be most gratefully received. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You could use the // Include the library
#include <Control_Surface.h>
// Instantiate a MIDI Interface to use
USBMIDI_Interface midi;
// Instantiate an analog multiplexer
CD74HC4067 mux{
A0, // Analog input pin
{ 2, 3, 4, 5 } // Address pins S0, S1, S2
};
NoteLED leds[]{
{ 1, { MIDI_Notes::C(4), CHANNEL_1 } }, // Note C4 on MIDI channel 1
{ 0, { MIDI_Notes::D(4), CHANNEL_1 } }, // Note D4 on MIDI channel 1
{ 6, { MIDI_Notes::E(4), CHANNEL_1 } }, // Note E4 on MIDI channel 1
{ 7, { MIDI_Notes::Gb(4), CHANNEL_1 } }, // Note F#4 on MIDI channel 1
{ 8, { MIDI_Notes::Ab(4), CHANNEL_1 } }, // Note G#4 on MIDI channel 1
{ 9, { MIDI_Notes::Bb(4), CHANNEL_1 } }, // Note A#4 on MIDI channel 1
{ 10, { MIDI_Notes::C(5), CHANNEL_1 } }, // Note C5 on MIDI channel 1
{ 14, { MIDI_Notes::D(5), CHANNEL_1 } }, // Note D5 on MIDI channel 1
{ 15, { MIDI_Notes::E(5), CHANNEL_1 } }, // Note E5 on MIDI channel 1
{ 16, { MIDI_Notes::Gb(5), CHANNEL_1 } }, // Note F#5 on MIDI channel 1
};
// Create an array of buttons that send out
// MIDI Control Change messages when pressed
CCButton buttons[]{
{ mux.pin(0), { MIDI_Notes::C(4), CHANNEL_1 } }, // GEN0
{ mux.pin(1), { MIDI_Notes::D(4), CHANNEL_1 } }, // GEN1
{ mux.pin(2), { MIDI_Notes::E(4), CHANNEL_1 } }, // GEN2
{ mux.pin(3), { MIDI_Notes::Gb(4), CHANNEL_1 } }, // GEN3
{ mux.pin(4), { MIDI_Notes::Ab(4), CHANNEL_1 } }, // GEN4
{ mux.pin(5), { MIDI_Notes::Bb(4), CHANNEL_1 } }, // GEN5
{ mux.pin(6), { MIDI_Notes::C(5), CHANNEL_1 } }, // GEN6
{ mux.pin(7), { MIDI_Notes::D(5), CHANNEL_1 } }, // GEN7
{ mux.pin(8), { MIDI_Notes::E(5), CHANNEL_1 } }, // GEN8
{ mux.pin(9), { MIDI_Notes::Gb(5), CHANNEL_1 } }, // FWD
{ mux.pin(10), { MIDI_Notes::Ab(5), CHANNEL_1 } }, // BCK
{ mux.pin(11), { MIDI_Notes::Bb(5), CHANNEL_1 } }, // SET
{ mux.pin(12), { MIDI_Notes::C(6), CHANNEL_1 } }, // G.C.
};
// Initialize the Control Surface
void setup() {
Control_Surface.begin();
for (auto &button : buttons)
button.invert();
}
// Update the Control Surface
void loop() {
Control_Surface.loop();
} Are you sure you want CCButtons and not NoteButtons? Mixing |
Beta Was this translation helpful? Give feedback.
You could use the
CCButton::invert()
function. For example: