MIDI controller - expected primary expression before token

Dears,

I am having a hard time (in a good way :slight_smile: ) trying to write a sketch for a keyboard MIDI controller.
What I am trying to do is essentially send MIDI CC’s from a 16 potentiometers Arduino - controller to a keyboard that can accept 32 different CC’s. When I press the “switch” button, the 16 pots send a new set of CC’s (one for each), and revert back to the first set of 16 CC’s when I press again the button.

I have the error in subject when trying to compile this:

#include <MIDI.h>

#define MIDI_CHANNEL 1 //the MIDI channel you set your keyboard to listen to (1-16)

// Created and binds the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();

const byte swButton = 2;
boolean switchState;
byte row = 0;

//Define Pots
byte pot[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
byte lastpot[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
//Define cc number for each pot
byte midi_cc[] = {24, 25, 3, 4, 5, 7, 8, 14, 11, 0, 12, 13, 22, 2, 23, 34};
//byte midi_cc[] = {9, 16, 17, 18, 19, 1, 20, 21, 26, 27, 28, 29, 30, 31, 32, 33};

void setup() {
pinMode(swButton, INPUT_PULLUP);
switchState = digitalRead(swButton);
}

void loop(){
if(digitalRead(swButton) != switchState){
  switchState = !switchState;
  if(switchState == LOW){row = !row;}
  if(row == 0){
    midi_cc[] = {24, 25, 3, 4, 5, 7, 8, 14, 11, 0, 12, 13, 22, 2, 23, 34};//page 1
  }
  else {
    midi_cc[] = {9, 16, 17, 18, 19, 1, 20, 21, 26, 27, 28, 29, 30, 31, 32, 33};//page 2
  }
  delay(300);} //cheap debounce
}

Any idea how could I solve this?

Thanks!!

Hi,
What Arduino board are you compiling for?
What version of the IDE are you using?
What OS?

Thanks Tom.. :slight_smile:

Hi,
Can you post your error messages, the IDE has a "Copy Error Messages" button which will copy the errors to clipboard.

Tom... :slight_smile:

Maybe your array assignments:

Thank you both.

I am using Arduino UNO and 1.6.11 IDE.

The full error log is

Arduino:1.6.11 (Windows 7), Scheda:"Arduino/Genuino Uno"

C:\Users\TM01314\AppData\Local\Temp\arduino_modified_sketch_204130\sketch_may11b.ino: In function 'void loop()':

sketch_may11b:29: error: expected primary-expression before ']' token

    midi_cc[] = {24, 25, 3, 4, 5, 7, 8, 14, 11, 0, 12, 13, 22, 2, 23, 34};//page 1

            ^

sketch_may11b:32: error: expected primary-expression before ']' token

    midi_cc[] = {9, 16, 17, 18, 19, 1, 20, 21, 26, 27, 28, 29, 30, 31, 32, 33};//page 2

            ^

exit status 1
expected primary-expression before ']' token

Questo report potrebbe essere più ricco di informazioni con l'opzione
"Mostra un output dettagliato durante la compilazione"
abilitata in File -> Impostazioni

I probably solved (only from a compile point of view) by making use of an array of arrays with my two set of values.

like this

#include <MIDI.h>

#define MIDI_CHANNEL 1 //the MIDI channel you set your JU to listen to (1-16)

// Created and binds the MIDI interface to the default hardware Serial port
MIDI_CREATE_DEFAULT_INSTANCE();

const byte swButton = 2;
boolean switchState;
boolean row = 0;

//Define Pots
byte pot[2][16] =       {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
byte lastpot[2][16] =   {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
                       {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
//Define cc number for each pot
byte midi_cc[2][16] =   {{24, 25, 3, 4, 5, 7, 8, 14, 11, 0, 12, 13, 22, 2, 23, 34},
                       {9, 16, 17, 18, 19, 1, 20, 21, 26, 27, 28, 29, 30, 31, 32, 33}};

void setup() {

pinMode(swButton, INPUT_PULLUP);
switchState = digitalRead(swButton);
}

void loop(){
if(digitalRead(swButton) != switchState){
 switchState = !switchState;
 if(switchState == LOW){row = !row;}
 delay(300); //cheap debounce
}
for (byte i = 0; i < 16; i++){
   pot[row][i] = analogRead(i) >>3;
   if(midi_cc[row][i] == 4 || midi_cc[row][i] == 5) {pot[row][i] = pot[row][i]/25;}//range 0 - 5
   else if (midi_cc[row][i] < 10){pot[row][i] = pot[row][i]/42;}//range 0 - 3
   if (lastpot[row][i] != pot[row][i]) {
     lastpot[row][i] = pot[row][i];
     MIDI.sendControlChange(midi_cc[row][i],pot[row][i],MIDI_CHANNEL);}
}
}