hi here's a script i've been working on using chat gpt keep getting an midi library error even though the library is installed and have tried all versions of the library this script uses MIDI.h by frances best.
i'm wanting a native usb midi device that will use latching machanical switches as i have quite a few of them knocking around so asked gpt to do edge detection i also wanted the abilty to use combinations of two switches at once to have more cc messages posible from the 6 switches i'm using so thats in there to with some delay for the dual presses to allow for timing issues with dual presses not being exactly at the same time i add slao debounce and pots with a change state to store current state and check against that before sending any cc changes to avoid any constant cc codes being sent any way here is the code and error if anyone can help.
the board is a pro micro which comes up as a leonardo not sure if this is an issue or not
#include <MIDI.h>
const int numPotentiometers = 5;
const int numSwitches = 6;
const int numCombinations = 2;
const int potentiometerPins[numPotentiometers] = {A0, A1, A2, A3, A4}; // Analog input pins for potentiometers
const int switchPins[numSwitches] = {2, 3, 4, 5, 6, 7}; // Digital input pins for switches
const int combinations[numCombinations][2] = {{2, 3}, {4, 5}}; // Switch combinations
const int ccCombination[numCombinations] = {10, 11}; // CC numbers for each combination
const int debounceDelay = 50; // Debounce delay in milliseconds
int potentiometerValues[numPotentiometers];
int switchStates[numSwitches];
int lastSwitchStates[numSwitches];
void setup() {
MIDI.begin();
for (int i = 0; i < numPotentiometers; i++) {
pinMode(potentiometerPins[i], INPUT);
}
for (int i = 0; i < numSwitches; i++) {
pinMode(switchPins[i], INPUT_PULLUP);
lastSwitchStates[i] = digitalRead(switchPins[i]);
}
}
void loop() {
// Read potentiometer values
for (int i = 0; i < numPotentiometers; i++) {
int value = analogRead(potentiometerPins[i]) / 8;
if (value != potentiometerValues[i]) {
potentiometerValues[i] = value;
MIDI.sendControlChange(i, value, 1);
}
}
// Read switch states with edge detection and debounce
for (int i = 0; i < numSwitches; i++) {
int state = digitalRead(switchPins[i]);
if (state != lastSwitchStates[i]) {
delay(debounceDelay);
state = digitalRead(switchPins[i]);
if (state != lastSwitchStates[i]) {
switchStates[i] = state;
MIDI.sendControlChange(i + numPotentiometers, state, 1);
handleSwitchStateChange(i);
}
}
lastSwitchStates[i] = state;
}
}
void handleSwitchStateChange(int switchIndex) {
int switchState = switchStates[switchIndex];
for (int i = 0; i < numCombinations; i++) {
if (switchPins[switchIndex] == combinations[i][0] || switchPins[switchIndex] == combinations[i][1]) {
MIDI.sendControlChange(ccCombination[i], switchState, 1);
break;
}
}
}
and the error in this code box
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino: In function 'void setup()':
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino:20:3: error: 'MIDI' was not declared in this scope
MIDI.begin();
^~~~
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino:20:3: note: suggested alternative: 'MISO'
MIDI.begin();
^~~~
MISO
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino: In function 'void loop()':
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino:38:7: error: 'MIDI' was not declared in this scope
MIDI.sendControlChange(i, value, 1);
^~~~
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino:38:7: note: suggested alternative: 'MISO'
MIDI.sendControlChange(i, value, 1);
^~~~
MISO
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino:50:9: error: 'MIDI' was not declared in this scope
MIDI.sendControlChange(i + numPotentiometers, state, 1);
^~~~
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino:50:9: note: suggested alternative: 'MISO'
MIDI.sendControlChange(i + numPotentiometers, state, 1);
^~~~
MISO
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino: In function 'void handleSwitchStateChange(int)':
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino:62:7: error: 'MIDI' was not declared in this scope
MIDI.sendControlChange(ccCombination[i], switchState, 1);
^~~~
C:\Users\pc\Documents\Arduino\midipedal\midipedal.ino:62:7: note: suggested alternative: 'MISO'
MIDI.sendControlChange(ccCombination[i], switchState, 1);
^~~~
MISO
exit status 1
Compilation error: 'MIDI' was not declared in this scope
any help welcome i'm not a coder but ahve made a few of these midi controller using other peoples scripts so understand what i need in one just can't seem to get this one working