Hi, I'm trying to build a USB interface for footswitch and expression pedals. Plug the pedals into the Arduino Pro Micro --> usb into the laptop. that allows you to use an expression pedal with a MIDI keyboard that doesnt have an exp pedal input, for example. anyways. The expression pedal input works fine. The problem is with the footswitch I try to plug. It only works as I intend it when I plug the footswitch into the pin3 of the Arduino Pro Micro. On any other pin, same code (except ofr pin number of course), it doesnt work. I really don't understand what I am doing, as it is a kinda simple sketch. buttons (footswitch) and potentiometer (expression pedal), basically.
In the IDE, I upload with the Sparkfun Pro Micro board and ATMEGA32U4 5V 16mhz processor.
The footswitch is wired up as any button should be. One leg into VCC, one into gnd with a 10k resistor, and it other one to the pin.
the code:
#include <MIDIUSB.h>
//***********************************************************************
//PINS
#define expPed1Pin A1
#define expPed2Pin A2
#define fs1Pin 3
#define fs2Pin 4
//EXPRESSION PEDAL 1
int potVal1;
int currentVal1;
int lastVal1;
//EXPRESSION PEDAL 2
int potVal2;
int currentVal2;
int lastVal2;
//FOOTSWITCH 1
int currentfs1state;
int lastfs1state;
//FOOTSWITCH 2
int currentfs2state;
int lastfs2state;
//***********************************************************************
void setup() {
Serial.begin(115200);
}
//***********************************************************************
void loop() {
// EXPRESSION PEDAL 1
currentVal1 = analogRead(expPed1Pin);
currentVal1 = map(currentVal1, 0, 1023, 0, 127);
if(currentVal1 != lastVal1)
{
controlChange(0, 11, currentVal1); // CHANNEL, CC, VALUE
MidiUSB.flush();
//Serial.println(currentVal1);
}
lastVal1 = currentVal1;
//**********************************************************************************************
// EXPRESSION PEDAL 2
currentVal2 = analogRead(expPed2Pin);
currentVal2 = map(currentVal2, 0, 1023, 0, 127);
if(currentVal2 != lastVal2)
{
controlChange(0, 11, currentVal2);
MidiUSB.flush();
//Serial.println(currentVal2);
}
lastVal2 = currentVal2;
//***********************************************************************************************
//FOOTSWITCH 1
currentfs1state = digitalRead(fs1Pin);
if (currentfs1state == 0 && lastfs1state == 1)
{
controlChange(0, 3, 127);
MidiUSB.flush();
//Serial.println(currentfs1state);
}
if (currentfs1state == 1 && lastfs1state == 0)
{
controlChange(0, 3, 0);
MidiUSB.flush();
//Serial.println(currentfs1state);
}
lastfs1state = currentfs1state;
//************************************************************************************************
//FOOTSWITCH 2
currentfs2state = digitalRead(fs2Pin);
if (currentfs2state == 0 && lastfs2state == 1)
{
controlChange(0, 64, 127);
MidiUSB.flush();
//Serial.println(currentfs2state);
}
if (currentfs2state == 1 && lastfs2state == 0)
{
controlChange(0, 64, 0);
MidiUSB.flush();
//Serial.println(currentfs2state);
}
lastfs2state = currentfs2state;
delay(1);
}
//***************************************************************************************************
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
The footswitch1, plugged into pin3 is working fine, but not the footswitch2, no matter on what pin I plug it.
Thank you so much for your help!