midi Program Change on two buttons midi Control Change on other two buttons

I am using a small four button midi controller I built to do Program changes. I’m using it to switch between amplifiers in a software program I use called Amplitube 4. It works great for that, but I would like to make another project that could use two buttons for midi Program change and two for midi Control Change.

Let me just say that I’ve researched a lot of material to get the 4 button midi switch I’m using now for Program Changes. I would have never got it to work until I stumbled on some excellent advice and code that Grumpy_Mike gave to another user in the Arduino forums. I was able to easily use that code to get my 4 button program change working. That thread is here:


The board I am using is a Sparkfun Pro Micro in my project box. The board I use to experiment with is an Arduino Leonardo. Both boards can do midi over USB.

So if anyone could help me understand what I need to do to incorporate Control Commands in my code
so I can use both Program change and Control change. I would like to use two of the buttons for Program Change and the other two for Control change. Below is the code I am using on my four button midi controller now.

// Simple MIDI output of program message through USB
// By Grumpy_Mike August 2019

#include "MIDIUSB.h"

// to add more then simply add more pins to the list
byte ledPin[] = {A0,A1,A2,A3};  // list of led pins
byte buttonPin[] = {3,4,5,6};    // list of buttons pins
byte buttonState[] = {0,0,0,0};  // start off with off
byte lastButtonState[] = {0,0,0,0};  // start off with off
byte programChanges[] = {0,1,2,3};  // list of program change messages to send

byte channel = 0; // for musicians this is channel 1

void setup() {
  for(int i =0;i< sizeof(buttonPin); i++){ // initialise input pins 
    pinMode(buttonPin[i], INPUT_PULLUP); // wire all buttons between input and ground
    pinMode(ledPin[i], OUTPUT);
void loop() {
  for(int i =0;i< sizeof(buttonPin); i++){  // look at all pins
  buttonState[i] = digitalRead(buttonPin[i]);
  if(buttonState[i] == LOW && lastButtonState[i] == HIGH) { // remember how you wired your buttons LOW = pressed
    programChange(channel, programChanges[i]); // send the program change message
   lastButtonState[i] = buttonState[i];

void ledOffAll() {
    for(int i = 0 ; i< sizeof(ledPin); i++){
     digitalWrite(ledPin[i], LOW);

void programChange(byte channel, byte patch) {
  midiEventPacket_t event = {0x0C, 0xC0 | channel, patch};

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