# Sending MIDI CC Value

**URL:** <https://forum.arduino.cc/t/sending-midi-cc-value/686355>\
**Category:** Programming\
**Created:** [December 9, 2020, 6:06pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355 "2020-12-09T18:06:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nigni83](https://avatars.discourse-cdn.com/v4/letter/n/eada6e/32.png) [@nigni83](https://forum.arduino.cc/u/nigni83)\
**Post date:** [December 9, 2020, 6:06pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/1 "2020-12-09T18:06:24Z")

</div>

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

```cpp
// ***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](https://ibb.co/DC4SH1C)  
thanks

---

<div class="post-metadata">

**Author:** ![PieterP](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@PieterP](https://forum.arduino.cc/u/PieterP)\
**Post date:** [December 9, 2020, 6:42pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/2 "2020-12-09T18:42:33Z")

</div>

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](https://github.com/tttapa/Control-Surface) library I maintain.  
Have a look at the [CCButton](https://tttapa.github.io/Control-Surface-doc/Doxygen/d9/d2e/CCButton_8ino-example.html) example, for instance.

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

```

Pieter

---

<div class="post-metadata">

**Author:** ![slipstick](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@slipstick](https://forum.arduino.cc/u/slipstick)\
**Post date:** [December 9, 2020, 6:45pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/3 "2020-12-09T18:45:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nigni83](https://avatars.discourse-cdn.com/v4/letter/n/eada6e/32.png) [@nigni83](https://forum.arduino.cc/u/nigni83)\
**Post date:** [December 9, 2020, 7:24pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/4 "2020-12-09T19:24:23Z")

</div>

Sorry, here the full code .

```cpp
#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;
      }
    }
  }
}
// *******************************************************************

```

---

<div class="post-metadata">

**Author:** ![PieterP](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@PieterP](https://forum.arduino.cc/u/PieterP)\
**Post date:** [December 9, 2020, 7:53pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/5 "2020-12-09T19:53:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![nigni83](https://avatars.discourse-cdn.com/v4/letter/n/eada6e/32.png) [@nigni83](https://forum.arduino.cc/u/nigni83)\
**Post date:** [December 9, 2020, 8:17pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/6 "2020-12-09T20:17:11Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![PieterP](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@PieterP](https://forum.arduino.cc/u/PieterP)\
**Post date:** [December 9, 2020, 8:18pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/7 "2020-12-09T20:18:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![slipstick](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@slipstick](https://forum.arduino.cc/u/slipstick)\
**Post date:** [December 9, 2020, 10:02pm UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/8 "2020-12-09T22:02:03Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:53am UTC](https://forum.arduino.cc/t/sending-midi-cc-value/686355/9 "2021-05-06T00:53:30Z")

</div>

Closed on May 6, 2021, 12:53am UTC


