Arduino MIDI Controller Patch/Bank programmming issue

Attached is my working code for a 12 button midi arduino. my Goal is 16 buttons which is easily doable for me so thats not the issue. I want to have a stepped(non-continuous) potientiometer with values of 1-4(4 different banks). value 1 (off position) should just be the default state of the controller (buttons correspond to notes attached in my code). In each of these banks i want 16 different notes or sounds. (one for each button). Could anyone please be so kind as to show me how to code these arrays? (code 4 banks to one pot and code 16 patches to each bank) PieterP can probably easily answer this if he sees it ive almost been able to get it working with his help

#include <MIDI.h>

MIDI_CREATE_DEFAULT_INSTANCE();

int middleCpin = 2;  
int cSharpPin = 3;   
int middleDpin = 4;  
int dSharpPin= 5;
int middleEpin = 6;
int middleFpin = 7;
int fSharpPin = 8;
int middleGpin = 9;
int gSharpPin = 10;
int middleApin = 11;
int aSharpPin = 12;
int middleBpin = 13;

int analogpot1 = A0;  //knob 1
int analogpot2 = A1;  //knob 2

int analogpot1Old = 0;
int analogpot2Old = 0;
int analogpot1New = 0;
int analogpot2New = 0;

#define analogpot1CC 54
#define analogpot2CC 55

void setup() {
  // put your setup code here, to run once:
MIDI.begin (); // MIDI START

pinMode(middleCpin, INPUT_PULLUP);
pinMode(cSharpPin, INPUT_PULLUP);
pinMode(middleDpin, INPUT_PULLUP);
pinMode(dSharpPin, INPUT_PULLUP);
pinMode(middleEpin, INPUT_PULLUP);
pinMode(middleFpin, INPUT_PULLUP);
pinMode(fSharpPin, INPUT_PULLUP);
pinMode(middleGpin, INPUT_PULLUP);
pinMode(gSharpPin, INPUT_PULLUP);
pinMode(middleApin, INPUT_PULLUP);
pinMode(aSharpPin, INPUT_PULLUP);
pinMode(middleBpin, INPUT_PULLUP);

pinMode(analogpot1, INPUT);
pinMode(analogpot2, INPUT);

//Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:

static bool middleCvalueOld = HIGH;
static bool cSharpValueOld = HIGH;
static bool middleDvalueOld = HIGH;
static bool dSharpValueOld = HIGH;
static bool middleEvalueOld = HIGH;
static bool middleFvalueOld = HIGH;
static bool fSharpValueOld = HIGH;
static bool middleGvalueOld = HIGH;
static bool gSharpValueOld = HIGH;
static bool middleAvalueOld = HIGH;
static bool aSharpValueOld = HIGH;
static bool middleBvalueOld = HIGH;

//footswitches
bool middleCvalueNew = digitalRead(middleCpin);
bool cSharpValueNew = digitalRead(cSharpPin);
bool middleDvalueNew = digitalRead(middleDpin);
bool dSharpValueNew = digitalRead(dSharpPin);
bool middleEvalueNew = digitalRead(middleEpin);
bool middleFvalueNew = digitalRead(middleFpin);
bool fSharpValueNew = digitalRead(fSharpPin);
bool middleGvalueNew = digitalRead(middleGpin);
bool gSharpValueNew = digitalRead(gSharpPin);
bool middleAvalueNew = digitalRead(middleApin);
bool aSharpValueNew = digitalRead(aSharpPin);
bool middleBvalueNew = digitalRead(middleBpin);


    if (middleCvalueNew != middleCvalueOld){
      if (middleCvalueNew == LOW){
      MIDI.sendNoteOn(60, 127, 1);
      //Serial.println("Note C On");
      }
      else {
      MIDI.sendNoteOff(60, 0, 1);
      //Serial.println("Note C Off");
      }
      middleCvalueOld = middleCvalueNew;
    }

      if (cSharpValueNew != cSharpValueOld){
      if (cSharpValueNew == LOW){
      MIDI.sendNoteOn(61, 127, 1);
      //Serial.println("Note E On");
      }
      else {
      MIDI.sendNoteOff(61, 0, 1);
      //Serial.println("Note E Off");
      }
      cSharpValueOld = cSharpValueNew;
    }

      if (middleDvalueNew != middleDvalueOld){
      if (middleDvalueNew == LOW){
      MIDI.sendNoteOn(62, 127, 1);
      //Serial.println("Note C On");
      }
      else {
      MIDI.sendNoteOff(62, 0, 1);
      //Serial.println("Note C Off");
      }
      middleDvalueOld = middleDvalueNew;
    }
    
      if (dSharpValueNew != dSharpValueOld){
      if (dSharpValueNew == LOW){
      MIDI.sendNoteOn(63, 127, 1);
      //Serial.println("Note E On");
      }
      else {
      MIDI.sendNoteOff(63, 0, 1);
      //Serial.println("Note E Off");
      }
      dSharpValueOld = dSharpValueNew;
    }
    
      if (middleEvalueNew != middleEvalueOld){
      if (middleEvalueNew == LOW){
      MIDI.sendNoteOn(64, 127, 1);
      //Serial.println("Note C On");
      }
      else {
      MIDI.sendNoteOff(64, 0, 1);
      //Serial.println("Note C Off");
      }
      middleEvalueOld = middleEvalueNew;
    }

      if (middleFvalueNew != middleFvalueOld){
      if (middleFvalueNew == LOW){
      MIDI.sendNoteOn(65, 127, 1);
      //Serial.println("Note C On");
      }
      else {
      MIDI.sendNoteOff(65, 0, 1);
      //Serial.println("Note C Off");
      }
      middleFvalueOld = middleFvalueNew;
    }

      if (fSharpValueNew != fSharpValueOld){
      if (fSharpValueNew == LOW){
      MIDI.sendNoteOn(66, 127, 1);
      //Serial.println("Note E On");
      }
      else {
      MIDI.sendNoteOff(66, 0, 1);
      //Serial.println("Note E Off");
      }
      fSharpValueOld = fSharpValueNew;
    }

     if (middleGvalueNew != middleGvalueOld){
      if (middleGvalueNew == LOW){
      MIDI.sendNoteOn(67, 127, 1);
      //Serial.println("Note C On");
      }
      else {
      MIDI.sendNoteOff(67, 0, 1);
      //Serial.println("Note C Off");
      }
      middleGvalueOld = middleGvalueNew;
    }

      if (gSharpValueNew != gSharpValueOld){
      if (gSharpValueNew == LOW){
      MIDI.sendNoteOn(68, 127, 1);
      //Serial.println("Note E On");
      }
      else {
      MIDI.sendNoteOff(68, 0, 1);
      //Serial.println("Note E Off");
      }
      gSharpValueOld = gSharpValueNew;
    }

   if (middleAvalueNew != middleAvalueOld){
      if (middleAvalueNew == LOW){
      MIDI.sendNoteOn(69, 127, 1);
      //Serial.println("Note C On");
      }
      else {
      MIDI.sendNoteOff(69, 0, 1);
      //Serial.println("Note C Off");
      }
      middleAvalueOld = middleAvalueNew;
    }
    
   if (aSharpValueNew != aSharpValueOld){
      if (aSharpValueNew == LOW){
      MIDI.sendNoteOn(70, 127, 1);
      //Serial.println("Note E On");
      }
      else {
      MIDI.sendNoteOff(70, 0, 1);
      //Serial.println("Note E Off");
      }
      aSharpValueOld = aSharpValueNew;
    }
    
     if (middleBvalueNew != middleBvalueOld){
      if (middleBvalueNew == LOW){
      MIDI.sendNoteOn(71, 127, 1);
      //Serial.println("Note C On");
      }
      else {
      MIDI.sendNoteOff(71, 0, 1);
      //Serial.println("Note C Off");
      }
      middleBvalueOld = middleBvalueNew;
    }

//potentiometers

int pot1 = analogRead(A0);
int pot2 = analogRead(A1);
int analogpot1New = analogRead(A0);
int analogpot2New = analogRead(A1);

    if (analogpot1New - analogpot1Old >= 35 || analogpot1Old - analogpot1New >= 35) {
      analogpot1Old = analogpot1New;
      analogpot1New = (map(analogpot1New, 1023, 0, 0, 120));
      analogpot1New = (constrain(analogpot1New, 0, 120));
      MIDI.sendControlChange(analogpot1CC, analogpot1New, 1);
//      Serial.print ("pot: ");
//      Serial.println(pot1);
//      Serial.print("potread: ");
//      Serial.println(analogpot1New); 
    }
    
    if (analogpot2New - analogpot2Old >= 35 || analogpot2Old - analogpot2New >= 35) {
      analogpot2Old = analogpot2New;
      analogpot2New = (map(analogpot2New, 1023, 0, 0, 120));
      analogpot2New = (constrain(analogpot2New, 0, 120));
      MIDI.sendControlChange(analogpot2CC, analogpot2New, 1);
//      Serial.print ("pot: ");
//      Serial.println(pot2);
//      Serial.print("potread: ");
//      Serial.println(analogpot2New); 
    }

delay(25);
}

midi_output.ino (6.93 KB)

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