Hey all, I'm trying to build a midi foot controller and to get it to do exactly what I'm looking for I decided to write my own code from scratch. I'm confident that the issue is easy to solve for someone with more coding knowledge than me but I seem to be totally stuck.
I'm using the MIDI.h library but am really only concerened with sending control change messages. Because I am a total novice when it comes to electronics and coding I started off with a 3 button prototype. I wanted to make the first button work as a sort of shift button, adding between 0 to 2 to the message value so I could effectively have the other two buttons act as six different buttons depending on the state of the first. Unsurprisingly my efforts to convert those aspirations to working code have proved uneffective. After booting up the midi to serial converter it just sends a control change value of 55 and 60 alternatively (seen in attached picture). Pressing the buttons does nothing to affect the messages. Heres my code, sorry there are no comments but if you have any questions I'd be happy to answer.
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
const int button1 = 2;
const int button2 = 3;
const int button3 = 4;
int fctr=0;
int button1Status = 0;
int button2Status = 0;
int button3Status = 0;
int midiVal1 = 55;
int midiVal2 = 60;
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
void setup() {
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(115200);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
}
void loop () {
buttonState1 = digitalRead(button1);
if ((fctr == 0)&& buttonState1 == HIGH){
fctr = 1;
}
if ((fctr == 1)&& buttonState1 == HIGH){
fctr = 2;
}
if ((fctr == 2)&& buttonState1 == HIGH){
fctr = 0;
}
buttonState2 = digitalRead(button2);
if (buttonState2 = HIGH){
MIDI.sendControlChange((midiVal1 + fctr), 127, 1);
} else {
MIDI.sendControlChange((midiVal1 + fctr), 0, 1);
}
buttonState3 = digitalRead(button3);
if (buttonState3 = HIGH){
MIDI.sendControlChange((midiVal2 + fctr), 128, 1);
} else {
MIDI.sendControlChange((midiVal2 + fctr), 0, 1);
}
}