Footswitch only working on pin 3 of Arduino Pro Micro

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!

The analogRead() can be used in the loop() without something in the setup().

The digitalRead() should have a pinMode() in setup(). But that does not explain your problem.

What is all that "flush()" for ? If you don't know, then you can remove them.

A digitalRead() returns HIGH or LOW, not 1 or 0. But that does not explain your problem.

Where/how is your pullup resistor ? Do you have a switch with three pins ? You can draw something (circuit or schematic) on paper or show a photo.


Ok so there's my breadboard. We don't see it but the + and - are connected between the two breadboard. The MIDI flush is part of the MIDIUSB library. It's meant to send MIDI data right away... I commented the lines and it doesnt change anything so I probably don't need that.
This is quarter inch jack. The switch has 2 pins (tip and sleeve) but I tried not using the ring pin on the socket and I cant get the Arduino to read anything.

Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.


Confirm with a DMM that action on the control can be observed on the Arduino pin.

I agree with LarryD.
Thank you for the good photo, but it is so confusing :confused: After staring at the photo for a while, I think it does not work. Pin 4 does not seem to have a pullup resistor.
Adding a potentiometer to a Arduino board and adding a switch to a Arduino board is no problem at all. However, you have wires to a jack plug, and now everything is fuzzy. I don't have a pedal lying around to open and see how it is wired.
You need a DMM (we call it a "multimeter" over here). If you don't have one, buy one.

On your picture I can only see one jack connector;

I'm not happy thats right. See my page here.

A schematic would be useful.

Your "setup" isnt setting up the digital inputs.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.