Hello everybody!
I am completely new to the work with Arduinos. I learned a bit of BASIC programming long time ago in high school, that’s all!
My project:
As a guitarist I want to integrate a midi controller into one of my electric guitars containing 10 switches. 9 (#2..10) of them shall send Program Change messages from 1-9, the last one (#16) should either modify the PCs to 11-19 or send a bank change command alternating between bank 0 and 1.
I got myself a Pro Micro ATmega32U4 Micro USB Board. And I started with a sketch auto-coded by Gustavo Silveira’s ARDUINO MIDI CONTROLLER CODE GENERATOR. Unfortunately the original sketch only sends Midi notes from buttons.
So my question is: How can I modify the sketch so send PC messages?
See line: // Send Program Change -- HELP!
Greetings from Germany
Hans
SKETCH:
// GOAL: MidiController with 10 Buttons
// 9 of these 10 Buttons send Program Changes, 1 Button (#16) alternates PCs between from 1-9 and from 11-19
#include <MIDIUSB.h>
#include <MIDIUSB_Defs.h>
/*
BASED ON: Made by Gustavo Silveira, 2023.
- This Sketch reads the Arduino's digital and analog ports and send midi notes and midi control change
MODIFIED to ProgramChanges
*/
/////////////////////////////////////////////
// Choosing your board
// Define your board, choose:
#define ATMEGA32U4 1 // put here the uC you are using, like in the lines above followed by "1", like "ATMEGA328 1", "DEBUG 1", etc.
/////////////////////////////////////////////
// Are you using buttons?
#define USING_BUTTONS 1 // comment if not using buttons
/////////////////////////////////////////////
// BUTTONS
#ifdef USING_BUTTONS
const int N_BUTTONS = 10; // total numbers of buttons
const int BUTTON_ARDUINO_PIN[10] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 16}; // pins of each button connected straight to the Arduino
int buttonCState[N_BUTTONS] = {}; // stores the button current value
int buttonPState[N_BUTTONS] = {}; // stores the button previous value
// debounce
unsigned long lastDebounceTime[N_BUTTONS] = { 0 }; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
#endif
/////////////////////////////////////////////
// MIDI
byte midiCh = 0; // MIDI channel to be used - start with 1 for MIDI.h lib or 0 for MIDIUSB lib
//byte note = 36; // Lowest note to be used
//byte cc = 1; // Lowest MIDI CC to be used
/////////////////////////////////////////////
// SETUP
void setup() {
Serial.begin(115200); //
#ifdef USING_BUTTONS
// Buttons
// Initialize buttons with pull up resistors
for (int i = 0; i < N_BUTTONS; i++) {
pinMode(BUTTON_ARDUINO_PIN[i], INPUT_PULLUP);
}
#endif
}
/////////////////////////////////////////////
// LOOP
void loop() {
#ifdef USING_BUTTONS
buttons();
#endif
}
/////////////////////////////////////////////
// BUTTONS
#ifdef USING_BUTTONS
void buttons() {
for (int i = 0; i < N_BUTTONS; i++) {
buttonCState[i] = digitalRead(BUTTON_ARDUINO_PIN[i]); // read pins from arduino
if ((millis() - lastDebounceTime[i]) > debounceDelay) {
if (buttonPState[i] != buttonCState[i]) {
lastDebounceTime[i] = millis();
if (buttonCState[i] == LOW) {
// Send Program Change -- HELP!
programchange???; // channel, note, velocity
MidiUSB.flush();
} else {
}
buttonPState[i] = buttonCState[i];
}
}
}
}
#endif
/////////////////////////////////////////////


