I've built several Arduino-based midi controllers to control my amps and effects. I am making a new one and for the life of me can't seem to get it to work. Here's the code:
#include <Bounce2.h>
#include <MIDI.h>
// Initialize MIDI on Serial (pin 1 for TX)
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
// Define button pins
const int buttonPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};// Amp models 1,3,7,5 - clean, slight, mod heavy, heavy - 2,3,4,5 Effects Mute, Boost, Phasor, Flang, Tremolo, Harmon - 6,7,8,9,10,11
// Define LED pins
const int leds[] = {12, 13, 14, 15, 16, 17, 18, 19, 20, 21}; // Amp models 1,3,7,5 - clean, slight, mod heavy, heavy - 12,13,14,15 Effects Mute, Boost, Phasor, Flang, Tremolo, Harmon - 16, 17, 18, 19, 20, 21
// Define MIDI messages for each button
const byte midiCC1[] = {1, 3, 7, 5, 7, 25, 19, 19, 19, 19}; // Mute, Boost, Phasor, Flanger, Tremolo, Harmonizer - button 6,7,8,9,10,11
const byte midiCC2[] = {1, 3, 7, 5, 7, 25, 58, 58, 58, 103}; // Mute, Boost, Phasor, Flanger, Tremolo, Harmonizer - button 6,7,8,9,10,11
const byte midiCC3[] = {1, 3, 7, 5, 7, 25, 28, 28, 28, 28}; // Mute, Boost, Phasor, Flanger, Tremolo, Harmonizer - button 6,7,8,9,10,11
const byte midiCC4[] = {1, 3, 7, 5, 7, 25, 34, 34, 34, 34}; // Mute, Boost, Phasor, Flanger, Tremolo, Harmonizer - button 6,7,8,9,10,11
const byte midiNote1[] = {1, 3, 7, 5, 127, 50, 1, 1, 1, 2}; // Amp models 1,3,7,5 - clean, slight, mod heavy, heavy - button 2,3,4,5
const byte midiNote2[] = {1, 3, 7, 5, 127, 50, 2, 3, 1, 2}; // Amp models 1,3,7,5 - clean, slight, mod heavy, heavy - button 2,3,4,5
const byte midiNote3[] = {1, 3, 7, 5, 127, 50, 127, 127, 127, 127}; // Amp models 1,3,7,5 - clean, slight, mod heavy, heavy - button 2,3,4,5
const byte midiNote4[] = {1, 3, 7, 5, 127, 50, 70, 79, 70, 30}; // Amp models 1,3,7,5 - clean, slight, mod heavy, heavy - button 2,3,4,5
byte midiToggle;
// Rename the Bounce array to avoid conflict
Bounce debouncers[10];
void setup() {
for (int i = 0; i < 10; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
debouncers[i].attach(buttonPins[i]);
debouncers[i].interval(40);
pinMode(leds[i], OUTPUT);
digitalWrite(leds[i], LOW); // Turn all LEDs off initially
}
// Begin MIDI communication on Serial
Serial.begin(31250); // Set Serial baud rate for MIDI
MIDI.begin(1);
}
void loop() {
for (int i = 0; i < 10; i++) {
debouncers[i].update(); // Update the debouncer state
if (debouncers[i].fell()) { // Button was just pressed
// If a button in group 1 (2,3,4,5) is pressed, turn off all LEDs in group 2 (6,7,8,9,10,11)
if (i < 5) {
for (int j = 5; j < 10; j++) {
digitalWrite(leds[j], LOW);
}
}
// Turn off all LEDs in the group of the pressed button
if (i < 5) {
for (int j = 0; j < 5; j++) {
digitalWrite(leds[j], LOW);
}
} else {
for (int j = 5; j < 10; j++) {
digitalWrite(leds[j], LOW);
}
}
// Turn on the LED for the pressed button
digitalWrite(leds[i], HIGH);
// Send MIDI messages
MIDI.sendProgramChange(midiCC1[i], 1);
//MIDI.sendControlChange(midiCC1[i], 127, 1);
//MIDI.sendControlChange(midiCC2[i], 127, 1);
//MIDI.sendControlChange(midiCC3[i], 127, 1);
//MIDI.sendControlChange(midiCC4[i], 127, 1);
//MIDI.sendNoteOn(midiNote1[i], 127, 1);
//MIDI.sendNoteOn(midiNote2[i], 127, 1);
//MIDI.sendNoteOn(midiNote3[i], 127, 1);
//MIDI.sendNoteOn(midiNote4[i], 127, 1);
// removed this line with debounce feature added "delay(100); // Original Debounce delay
}
}
}
I have commented out all but the most essential lines that control the midi messages. At this point, the code is super similar to another controller I made using a Mega. Now I'm using a Due.
Serial off pin 1.
I just need to send a midi PC of 1, 3, 5, or 7 (picks the amp model on my guitar ampler). Once that is working, I can focus on the effects information.
Any help would be really appreciated! Thanks!