Sending MIDI CC Value

Hello, I've made a midi Footswitch and I should send a range Value (0-127) on a specific CC number.
My partial sketch is

//***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, 2, 11, 1, 50 );
Button BU2(3, 2, 12, 1, 50 );
Button BU3(4, 2, 13, 1, 50 );
Button BU4(5, 2, 68, 1, 50 );
Button BU5(6, 2, 7, 1, 50 );
Button BU6(7, 2, 8, 1, 50 );
Button BU7(8, 2, 9, 1, 50 );
Button BU8(9, 2, 64, 1, 20 );

I can send a CC number but not its Value, how can I do?
in the pic the example of what I need
PHOTO
thanks

1 Like

Please post your full code if you want help with it.

If you just want a working MIDI controller/footswitch, you might be interested in the Control Surface library I maintain.
Have a look at the CCButton example, for instance.

CCButton expr1 {
  2,        // pin
  1,        // MIDI CC#
  {127, 0}, // (value when pressed, value when released)
};

Pieter

1 Like

There's nothing in that code that does anything at all. Would you like to post the rest of your best attempt e.g. the code that sends CC numbers but not values? Then we'll have somewhere to start from.

Steve

Sorry, here the full 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, 2, 11, 1, 50 );
Button BU2(3, 2, 12, 1, 50 );
Button BU3(4, 2, 13, 1, 50 );
Button BU4(5, 2, 68, 1, 50 );
Button BU5(6, 2, 7, 1, 50 );
Button BU6(7, 2, 8, 1, 50 );
Button BU7(8, 2, 9, 1, 50 );
Button BU8(9, 2, 64, 1, 20 );
//*******************************************************************
//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);
  pinMode(10, OUTPUT);
}

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


//*****************************************************************
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);                       
          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;
      }
    }
  }
}
//*******************************************************************

What do you need help with? That code seems to send MIDI CC messages with values of 0 and 127, why doesn't that match your expectations?

My problem Is that i would like decide which value send for a specific CC Number, be free to choose from 0 to 127 ( maybe 64 for example)

Based on what? Hardcoding the value is easy, if you want to change it at run-time (e.g. depending on user input), you'll have to explain how it should behave and post your attempts.

nigni83:
My problem Is that i would like decide which value send for a specific CC Number, be free to choose from 0 to 127 ( maybe 64 for example)

So put a variable in place of the 0 and 127 and set that variable to whatever value you want based on whatever you think appropriate.

Steve