// FM3 Scenes Contoller 28-Nov-2023 V2.3
#include <MIDI.h>
// https://github.com/FortySevenEffects/arduino_midi_library
#include <ezButton.h>
// https://arduinogetstarted.com/library/button/example/arduino-button-array
MIDI_CREATE_DEFAULT_INSTANCE();
const int BUTTON_1_PIN = 9; // define the pins where the switches are connected at the Arduino board
const int BUTTON_2_PIN = 8;
const int BUTTON_3_PIN = 7;
const int BUTTON_4_PIN = 6;
const int BUTTON_5_PIN = 5;
const int BUTTON_6_PIN = 4;
const int BUTTON_7_PIN = 3;
const int BUTTON_8_PIN = 2;
#define MIDICHAN 1 //MIDI channel
#define SceneCC 34 //CC for scene. Define the MIDI CC you want to send to the device
const int BUTTON_NUM = 8; //*** total number of buttons
ezButton buttonArray[] = {
ezButton(BUTTON_1_PIN),
ezButton(BUTTON_2_PIN),
ezButton(BUTTON_3_PIN),
ezButton(BUTTON_4_PIN),
ezButton(BUTTON_5_PIN),
ezButton(BUTTON_6_PIN),
ezButton(BUTTON_7_PIN),
ezButton(BUTTON_8_PIN)
};
void setup() {
Serial.begin(9600);
MIDI.begin(1);
for (byte i = 0; i < BUTTON_NUM; i++) {
buttonArray[i].setDebounceTime(50); // set debounce time to 50 milliseconds
}
}
void loop() {
for (byte i = 0; i < BUTTON_NUM; i++) {
buttonArray[i].loop(); // MUST call the loop() function first
if (buttonArray[i].isPressed()) { // detect pressed button
MIDI.sendControlChange(SceneCC, i, MIDICHAN); // Send the MIDI data
break;
}
}
}