Go Down

Topic: Midi Footcontroller switch problem (Read 9171 times) previous topic - next topic


not pressed
pins D2- D6 4.9v
D7-D9- 0v
D10-12 4.9v

A0-A5 4.9v

when Pressed

D2-D5 0v
D10-D12 0v

A0-A3 0v

When the bank button up or down is pressed the leds flash like he says in his instructions these pins are
D6 0.5-0v
D7 3.1v-0v
D8 2.3v-0.3v
D9 2.6v - 0.1v


Have you tried running the program in debug mode?

This prints out at 9600 bauds to the serial monitor what would normally be sent as MIDI.

To put it into this mode put
Code: [Select]
#define DEBUG
Just after all the #include statements.

When I do this it shows that pin 10 shows a control change message of controller 1, value 0 or 1, and  pin 11 shows a control change message of controller 3, value 0 or 1.

Is this the sort of controller message your system is expecting? I know some MIDI controllers want the values 0 or 127 to be effective.



 switch 1 pin 10 it says midi control change 80 0 and switch on

midi control change 80 1

Pin 11 says

midi control change 83 1
midi control change 80 0

83 and 80 are the cc i have dialed in

just with what you saying about my effects units i think your right i think they need a number between 0 -127

I got a sketch that just turns a reverb on and off by sending a cc and it works perfectly it does send a 0 value for off and 127 for on.


OK to change it to send 127 instead of just 1 then make the changes to this function:-
Code: [Select]
void ExecExtraButtons(byte ButId){
  if (ButId == S1){
    sendControlChange(Storage.readS1CC(currprog-1), S1state() ? 127 : 0);  // Send the value to the given controller defined in the array

  if (ButId == S2){
      sendControlChange(Storage.readS2CC(currprog-1), S2state() ? 127 : 0);  // This is Kemper-Amp only. Means turn Stomp A on/off
      // In my case this switches the Wah effect on/off
      // Volume pedal becomes Wah pedal!

  digitalWrite(LS1,S1state() ? HIGH : LOW);  // let the LED reflect the current state
  digitalWrite(LS2,S2state() ? HIGH : LOW);   


Brilliant!!! it works, thanks for all your help Mike appreciate it.

Is it possible to send 2 midi commands from one button like a program change and a cc at once like button 2 will always send program message and the same cc message MidiCc(1,83,127) and MidiCc(1,83,0)?

Also would it be hard to incorporate another button into the sketch for sending Midi cc like for example,

// pin to use for indicator LED
int ledPin = 12;
// pin that is connected to the footswitch
int buttonPin = A0;

int buttonState = 0;
int buttonLastState = 0;
int buttonInitState = 0;

int muteStatus = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  // Setup serial port for MIDI communication
  // read current button state, a press is detected whenever
  // state changes to anything else than the init state
  buttonInitState = digitalRead(buttonPin);
  // we only want to do something on state changes
  buttonLastState = buttonInitState;

void loop() {
  buttonState = digitalRead(buttonPin);
  // has the state changed?
  if (buttonState != buttonLastState) {
    buttonLastState = buttonState;
    if (buttonState != buttonInitState) {
      // button is in pressed state, trigger action
      if (muteStatus == 0) {
        // mute and light up LED
        digitalWrite(ledPin, HIGH);
        // send CC 85 on channel 1 with value 0 to mute
        // mute group 6 on a effects loop
        midiCc(1, 80, 0);
        muteStatus = 1;
      } else {
        // unmute and turn off LED
        digitalWrite(ledPin, LOW);
        midiCc(1, 80, 127);
        muteStatus = 0;
    // workaround to prevent fluttering of button state

void midiCc(int channel, int command, int value) {
  Serial.write(175 + channel);


Is it possible to send 2 midi commands from one button like a program change and a cc at once
Yes this is possible.

Also would it be hard to incorporate another button into the sketch
It would be possible but not easy given that the code you have uses a convoluted system of reading all the switches in an interrupt service routine ( ISR ) and trying to debounce them.

Now when posting code here you have to use code tags, either the </> icon at the top left and paste the code between them or use the IDE's "copy for forum" which now works after many years of it not doing.


Cheers Mike thanks for that.



Im not sure if this should be a new thread or not so forgive me, it is related though.

I am trying to put an other switch (S3 entry in the code) to work independently for switching a fixed cc on and off.
i have been experimenting and i have managed to get it to turn it off but not back on i know the code is wrong, when i debug it the switch is reading the cc number and a value of 127 when pressed or depressed.

any help would be great.


Jan 27, 2016, 11:49 am Last Edit: Jan 27, 2016, 11:49 am by Grumpy_Mike
You are not checking the state of button 3 you are just testing the ID that shows this button has changed.
Look at the other buttons, they look at the state of the button to decide what to send.

Also that else on button 3 is wrong. The way you have it is that if any of the other buttons is pressed you will send control changes 80 with a value of zero. That is not what you want.


Do I have to put in an independent button state for the new S3 button?.



i have put in a new button with its own read state its compiling, but its still not working when debugged.


Yes but you still have to do something when you see the button.
What do you think this code is doing?
Code: [Select]
if (ButId == S3){


Let me tell you, it is doing nothing, which is why nothing happens when you press the button.


I have ignored that switch and put in a new one labeled button 1 and at the end of the code i have put a button state and change control for button 1. I should of tided the S3 switch up.


Tidied up sketch.

Go Up