#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
// Define potentiometer pins
const int potPins[] = {34, 35, 32};
const int numPots = sizeof(potPins) / sizeof(potPins[0]);
int potValues[numPots];
// Define button pins
const int buttonPins[] = {25, 26, 27};
const int numButtons = sizeof(buttonPins) / sizeof(buttonPins[0]);
bool buttonStates[numButtons];
void setup() {
Serial.begin(115200);
MIDI.begin(MIDI_CHANNEL_OMNI);
// Initialize potentiometer pins
for (int i = 0; i < numPots; i++) {
pinMode(potPins[i], INPUT);
}
// Initialize button pins
for (int i = 0; i < numButtons; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
}
void loop() {
// Read potentiometer values and send MIDI CC
for (int i = 0; i < numPots; i++) {
int value = analogRead(potPins[i]) / 8; // Scale 0-4095 to 0-127
if (value != potValues[i]) {
potValues[i] = value;
MIDI.sendControlChange(i + 1, value, 1); // CC number, value, channel
}
}
// Read button states and send MIDI CC
for (int i = 0; i < numButtons; i++) {
bool state = digitalRead(buttonPins[i]) == LOW; // Button pressed
if (state != buttonStates[i]) {
buttonStates[i] = state;
MIDI.sendControlChange(i + numPots + 1, state ? 127 : 0, 1); // CC number, value, channel
}
}
delay(10); // Adjust delay as needed
}