Send ProgramChange via Midi

Hello i m a biginner, my project is to send ProgramChange data via Midi to a guitar on a pedalboard.
I need to send PC from 0 to 7 on channel 1
i found a sketch online that allow to use buttons , pots and mux buttons.. i've edited for buttons only but i m able to send just 0 and 1 signal, other 6 buttons wont work.
i used pins 2 to 9 .
the sketch is attached, hope someone will help me.

Controller.cpp (3.99 KB)

Controller.h (1.7 KB)

MIDI_Controller_v1-2_button_multipli.ino (5.17 KB)

If you read "How to use this forum" at the top of every forum it will tell you how to post your code inline in the message. THEN you'll stand a better chance of getting some help.

Steve

i m so sorry, i was writing from a pc with no arduino installed, i hope this is fine now

Ps: to avoid mistakes i didn't delete useless strings

[code]
#include <MIDI.h>
#include "Controller.h"


MIDI_CREATE_DEFAULT_INSTANCE();

//************************************************************
//***SET THE NUMBER OF CONTROLS USED**************************
//************************************************************
//---How many buttons are connected directly to pins?---------
byte NUMBER_BUTTONS = 8;
//---How many potentiometers are connected directly to pins?--
byte NUMBER_POTS = 0;
//---How many buttons are connected to a multiplexer?---------
byte NUMBER_MUX_BUTTONS = 0;
//---How many potentiometers are connected to a multiplexer?--
byte NUMBER_MUX_POTS = 0;
//************************************************************


Pot *POTS[] {};
//*******************************************************************


//***DEFINE DIRECTLY CONNECTED BUTTONS*******************************
//Button (Pin Number, Command, Note Number, Channel, Debounce Time)
//** Command parameter 0=NOTE  1=CC  2=Toggle CC **

Button BU1(2, 1, 0, 1, 5 );
Button BU2(3, 1, 1, 1, 5 );
Button BU3(4, 1, 2, 1, 5 );
Button BU4(5, 1, 3, 1, 5 );
Button BU5(6, 1, 4, 1, 5 );
Button BU6(7, 1, 5, 1, 5 );
Button BU7(8, 1, 6, 1, 5 );
Button BU8(9, 1, 7, 1, 5 );
//*******************************************************************
//Add buttons used to array below like this->  Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
Button *BUTTONS[] {&BU1, &BU2, &BU3, &BU4, &BU5, &BU6, &BU7, &BU8};
Button *MUXBUTTONS[] {};
Pot *MUXPOTS[] {};
//*******************************************************************


void setup() {
  MIDI.begin(MIDI_CHANNEL_OFF);
}

void loop() {
  if (NUMBER_BUTTONS != 0) updateButtons();
  if (NUMBER_POTS != 0) updatePots();
  if (NUMBER_MUX_BUTTONS != 0) updateMuxButtons();
  if (NUMBER_MUX_POTS != 0) updateMuxPots();
}


//*****************************************************************
void updateButtons() {

  // Cycle through Button array
  for (int i = 0; i < NUMBER_BUTTONS; i = i + 1) {
    byte message = BUTTONS[i]->getValue();

    //  Button is pressed
    if (message == 0) {
      switch (BUTTONS[i]->Bcommand) {
        case 0: //Note
          MIDI.sendNoteOn(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
          break;
        case 1: //CC
          MIDI.sendProgramChange(BUTTONS[i]->Bvalue, BUTTONS[i]->Bchannel);                       // RIGA DI ERRORE PER LEO
          break;
        case 2: //Toggle
          if (BUTTONS[i]->Btoggle == 0) {
            MIDI.sendControlChange(BUTTONS[i]->Bvalue, 127, BUTTONS[i]->Bchannel);
            BUTTONS[i]->Btoggle = 1;
          }
          else if (BUTTONS[i]->Btoggle == 1) {
            MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
            BUTTONS[i]->Btoggle = 0;
          }
          break;
      }
    }

    //  Button is not pressed
    if (message == 1) {
      switch (BUTTONS[i]->Bcommand) {
        case 0:
          MIDI.sendNoteOff(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
          break;
        case 1:
          MIDI.sendControlChange(BUTTONS[i]->Bvalue, 0, BUTTONS[i]->Bchannel);
          break;
      }
    }
  }
}
//*******************************************************************
void updateMuxButtons() {

  // Cycle through Mux Button array
  for (int i = 0; i < NUMBER_MUX_BUTTONS; i = i + 1) {

    MUXBUTTONS[i]->muxUpdate();
    byte message = MUXBUTTONS[i]->getValue();

    //  Button is pressed
    if (message == 0) {
      switch (MUXBUTTONS[i]->Bcommand) {
        case 0: //Note
          MIDI.sendNoteOn(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
          break;
        case 1: //CC
          MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
          break;
        case 2: //Toggle
          if (MUXBUTTONS[i]->Btoggle == 0) {
            MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 127, MUXBUTTONS[i]->Bchannel);
            MUXBUTTONS[i]->Btoggle = 1;
          }
          else if (MUXBUTTONS[i]->Btoggle == 1) {
            MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
            MUXBUTTONS[i]->Btoggle = 0;
          }
          break;
      }
    }
    //  Button is not pressed
    if (message == 1) {
      switch (MUXBUTTONS[i]->Bcommand) {
        case 0:
          MIDI.sendNoteOff(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
          break;
        case 1:
          MIDI.sendControlChange(MUXBUTTONS[i]->Bvalue, 0, MUXBUTTONS[i]->Bchannel);
          break;
      }
    }
  }
}
//***********************************************************************
void updatePots() {
  for (int i = 0; i < NUMBER_POTS; i = i + 1) {
    byte potmessage = POTS[i]->getValue();
    if (potmessage != 255) MIDI.sendControlChange(POTS[i]->Pcontrol, potmessage, POTS[i]->Pchannel);
  }
}
//***********************************************************************
void updateMuxPots() {
  for (int i = 0; i < NUMBER_MUX_POTS; i = i + 1) {
    MUXPOTS[i]->muxUpdate();
    byte potmessage = MUXPOTS[i]->getValue();
    if (potmessage != 255) MIDI.sendControlChange(MUXPOTS[i]->Pcontrol, potmessage, MUXPOTS[i]->Pchannel);
  }
}

[/code]

#include "Controller.h" we can not see what the functions are that are hidden in here. It's hardly a midi issue, maybe you should change the topic name as well.

All the files are in the attach, if you want spend a few mins for me i ll be glad

Where did you get that Controller library from? A link would be good. Perhaps there is some documentation for it.

Steve

I ve downloaded sketch and library from this link , im a newbie Notes and Volts: Arduino MIDI Controller: Buttons

O.k. so no useful documentation. Perhaps you can tell us again what exactly happens when you try all the buttons? What is on the other end of the MIDI connection? Do you have some program like MIDI-OX which is showing you the MIDI messages that are being sent. If so please post the results here. Or if not how do you know things aren't working?

From what little I can tell the code looks o.k.

The difficulty with this internet problem solving it that we can't see what you can see and we don't know anything about your setup unless you've thought to tell us.

Steve

i think have found the problem... it seems impossible but 6 o 8 buttons are broken O.O .. i used arduino few times and the buttons given in the kit seems to be not working... i used other buttons and now it works... i m so sorry for the time i stole you but i cant imagine how it can be happen... i ll make other test but it seems work with differents buttons... i can just thank you so much for your time and hope to learn from my errors... thank you again my friend!

Glad you got it going. If you're using the normal 4-pin "button" switches it may be worth checking that you have them the right way round. Many of them will look like they're not working if they are turned through 90 degrees so you're actually connecting the wrong 2 pins.

Steve