Need help with Arduino: Scene Change randomly selects preset 34 instead of CC34

Piing

Axe-Master
I am building an Arduino foot controller that so far has the following features:


- 15 Pedal Switches (3 rows of 5)

- First row, switches 1-5: patch selection

- Second row, switches 1-4: Select Scene 1 to 4

- Second row, switch 5: Bank Down

- Third row, switches 1-4: Looper control

- Third row, switch 5: Bank Up


Everything is working fine except the Scene Changes (Switches 6 to 9). When I press the switches for the first time they correctly select the scene at the Axe-FX, but when I have been pressing switches for a while, they select preset 34 instead of the Scene (for one instant) and then select the preset with the same number of the scene.


Any help will be much appreciated. I’ve already spent ages trying to catch the bug.


Here is the code:

ps: I cannot insert the code here because its too long . I will try it at the next post
 
Last edited:
Code part 1 of 2:
Code:
// Axe-FX midi.controller 05-Oct-2016
// V4.4
#include <MIDI.h>  //Midi library Version 3.2
#include <LiquidCrystal.h>

#define SWITCH1 22
#define SWITCH2 24
#define SWITCH3 26
#define SWITCH4 28
#define SWITCH5 30
#define SWITCH6 32
#define SWITCH7 34
#define SWITCH8 36
#define SWITCH9 38
#define SWITCH10 40
#define SWITCH11 42
#define SWITCH12 44
#define SWITCH13 46
#define SWITCH14 48
#define SWITCH15 50
#define SWITCH16 52
#define SWITCH17 14
#define SWITCH18 15
#define SWITCH19 16
#define SWITCH20 17

#define LED1 23
#define LED2 25
#define LED3 27
#define LED4 29
#define LED5 31
#define LED6 33
#define LED7 35
#define LED8 37
#define LED9 39
#define LED10 41
#define LED11 43
#define LED12 45
#define LED13 47
#define LED14 49
#define LED15 51
#define LED16 53
#define LED17 18
#define LED18 19
#define LED19 20
#define LED20 21

#define MIDICHAN 1 //MIDI channel
#define FX1CC 23   //CC channel for FX1    
#define FX2CC 25   //CC channel for FX2 (Ext 8 on Axe)
#define FX2ndCC 16 //CC for 2nd git's FX
#define VOLPEDCC 11 //CC to control overall Axe volume
#define TUNERCC 15  //CC to engage tuner
#define CLEAN1stCC 100  //CC for 1st git's clean channel
#define CLEAN2ndCC 101  //CC for 2nd git's clean channel
#define EXP0CC 22  //CC for expression pedal 0
#define EXP1CC  24
#define EXP2CC 18  //Ext 4
#define SceneCC 34 //CC for scene
#define LoopRecordCC  28
#define LoopPlayCC  29
#define LoopOnceCC  30
#define LoopDubCC  31
#define LoopRevCC  32
#define LoopBypassCC  33
#define LoopHalfCC  120
#define LoopUndoCC  121

#define BOUNCEDELAY 25


/* LCD definition
* LCD RS pin to digital pin 8
* LCD Enable pin to digital pin 9
* LCD D4 pin to digital pin 4
* LCD D5 pin to digital pin 5
* LCD D6 pin to digital pin 6
* LCD D7 pin to digital pin 7
* LCD BL pin to digital pin 10
* KEY pin to analogl pin 0
*/
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);



// Variables:
int switches[20] = { SWITCH1, SWITCH2, SWITCH3, SWITCH4, SWITCH5, SWITCH6, SWITCH7, SWITCH8,
                    SWITCH9, SWITCH10, SWITCH11, SWITCH12, SWITCH13, SWITCH14, SWITCH15, SWITCH16,SWITCH17, SWITCH18, SWITCH19, SWITCH20};
int switchState[20] = { HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH , HIGH , HIGH , HIGH  };
// Initial state of switch is high due to internal pullup
int Toggle[20] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 , 1 , 1 , 1};
int leds[20] = { LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8, LED9, LED10, LED11, LED12, LED13, LED14, LED15, LED16, LED17, LED18, LED19, LED20 };
int currentSwitch = 0;
int pedalActiveFlash = 50; // Delay for flash when pedal is pressed
int PresetNumb = 0; //Initial preset number for preset selection

void setup() {

//  LCD Initial Message
  lcd.clear();
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("AxeFX Controller");

//  Set MIDI baud rate:
  Serial.begin(31250);
  //Serial.begin(9600);

// Setup Switches and activate LEDs
  for( currentSwitch = 0; currentSwitch < 20; currentSwitch++ ) {
    pinMode( switches[currentSwitch], INPUT_PULLUP);          // Set pin for switch
    digitalWrite( switches[currentSwitch], HIGH );      // Turn on internal pullup
    pinMode( leds[currentSwitch], OUTPUT );             // Set pin for LED
  flashPin( leds[currentSwitch], 100 ); // Flash LED
  }
}

void loop() {

  for( currentSwitch = 0; currentSwitch < 20; currentSwitch++ ) {
    if((digitalRead(switches[currentSwitch]) != switchState[currentSwitch] )&&(switchState[currentSwitch] == HIGH)){
      switch( currentSwitch ) {

// Switch 1.                            Select preset on switch 1
        case 0:
              midiProg(0xC0, PresetNumb);
              digitalWrite( LED1, HIGH);
              digitalWrite( LED2, LOW);
              digitalWrite( LED3, LOW);
              digitalWrite( LED4, LOW);
              digitalWrite( LED5, LOW);
              lcd.clear();   lcd.begin(16, 2);  lcd.setCursor(0,0); lcd.print(PresetNumb); lcd.print("-");lcd.print(PresetNumb+4);
              lcd.setCursor(7,0);   lcd.print("Preset "); lcd.print(PresetNumb);
        break;

// Switch 2.                            Select preset on switch 2
        case 1:
              midiProg(0xC0, PresetNumb+1);
              digitalWrite( LED1, LOW);
              digitalWrite( LED2, HIGH);
              digitalWrite( LED3, LOW);
              digitalWrite( LED4, LOW);
              digitalWrite( LED5, LOW);
              lcd.clear();   lcd.begin(16, 2);  lcd.setCursor(0,0); lcd.print(PresetNumb); lcd.print("-");lcd.print(PresetNumb+4);
              lcd.setCursor(7,0);   lcd.print("Preset "); lcd.print(PresetNumb+1);
        break;
 
Code part 2 of 2:

Code:
// Switch 3.                          Select preset on switch 3
        case 2:
              midiProg(0xC0, PresetNumb+2);
              digitalWrite( LED1, LOW);
              digitalWrite( LED2, LOW);
              digitalWrite( LED3, HIGH);
              digitalWrite( LED4, LOW);
              digitalWrite( LED5, LOW);
              lcd.clear();   lcd.begin(16, 2);  lcd.setCursor(0,0); lcd.print(PresetNumb); lcd.print("-");lcd.print(PresetNumb+4);
              lcd.setCursor(7,0);   lcd.print("Preset "); lcd.print(PresetNumb+2);
        break;

// Switch 4.                            Select preset on switch 4
        case 3:
              midiProg(0xC0, PresetNumb+3);
              digitalWrite( LED1, LOW);
              digitalWrite( LED2, LOW);
              digitalWrite( LED3, LOW);
              digitalWrite( LED4, HIGH);
              digitalWrite( LED5, LOW);
              lcd.clear();   lcd.begin(16, 2);  lcd.setCursor(0,0); lcd.print(PresetNumb); lcd.print("-");lcd.print(PresetNumb+4);
              lcd.setCursor(7,0);   lcd.print("Preset "); lcd.print(PresetNumb+3);
        break;

// Switch 5.                            Select preset on switch 5
        case 4:
              midiProg(0xC0, PresetNumb+4);
              digitalWrite( LED1, LOW);
              digitalWrite( LED2, LOW);
              digitalWrite( LED3, LOW);
              digitalWrite( LED4, LOW);
              digitalWrite( LED5, HIGH);
              lcd.clear();   lcd.begin(16, 2);  lcd.setCursor(0,0); lcd.print(PresetNumb); lcd.print("-");lcd.print(PresetNumb+4);
              lcd.setCursor(7,0);   lcd.print("Preset "); lcd.print(PresetNumb+4);
        break;


       
// Switch 6.                            Scene 1
        case 5:
              MIDI.sendControlChange(SceneCC, 0, MIDICHAN);
              digitalWrite( LED6, HIGH);
              digitalWrite( LED7, LOW);
              digitalWrite( LED8, LOW);
              digitalWrite( LED9, LOW);
              lcd.setCursor(0,1);   lcd.print("       Scene 1");
        break;
       
// Switch 7.                            Scene 2
        case 6:
              MIDI.sendControlChange(SceneCC, 1, MIDICHAN);
              digitalWrite( LED6, LOW);
              digitalWrite( LED7, HIGH);
              digitalWrite( LED8, LOW);
              digitalWrite( LED9, LOW);
              lcd.setCursor(0,1);   lcd.print("       Scene 2");
          break;
         
// Switch 8.                            Scene 3         
        case 7:
              MIDI.sendControlChange(SceneCC, 2, MIDICHAN);
              digitalWrite( LED6, LOW);
              digitalWrite( LED7, LOW);
              digitalWrite( LED8, HIGH);
              digitalWrite( LED9, LOW);
              lcd.setCursor(0,1);   lcd.print("       Scene 3");
        break;

// Switch 9.                            Scene 4           

        case 8:
               MIDI.sendControlChange(SceneCC, 3, MIDICHAN);
              digitalWrite( LED6, LOW);
              digitalWrite( LED7, LOW);
              digitalWrite( LED8, LOW);
              digitalWrite( LED9, HIGH);
              lcd.setCursor(0,1);   lcd.print("       Scene 4");
          break;

// Switch 10.                         Bank Down
        case 9:
         //PresetNumb=PresetNumb-95;
         if (PresetNumb<5) PresetNumb=95; else if (PresetNumb=PresetNumb-5);
         flashPin( leds[currentSwitch], pedalActiveFlash );
         lcd.clear();lcd.setCursor(0,0); lcd.print(PresetNumb); lcd.print("-");lcd.print(PresetNumb+4);
          break;

// Switch 11.                         Loop Record
        case 10:
          MIDI.sendControlChange(LoopRecordCC, 0, MIDICHAN);
          flashPin( leds[currentSwitch], pedalActiveFlash );
          lcd.setCursor(0,2); lcd.print("                 ");
          lcd.setCursor(0,2); lcd.print("Loop RECORD");
      //Toggle Display
      {
      if (Toggle[currentSwitch] == 1) {
          // Toggle on
          digitalWrite(leds[currentSwitch], HIGH);
          lcd.setCursor(0,2); lcd.print("                 ");lcd.setCursor(0,2); lcd.print("Loop RECORD     ");
          Toggle[currentSwitch] = 0;
      } else {
          // Toggle off
          digitalWrite(leds[currentSwitch], LOW);
          lcd.setCursor(0,2); lcd.setCursor(0,2); lcd.print("                 ");
          Toggle[currentSwitch] = 1;   
        }
  }
         
          break;

// Switch 12.                         Loop Play     
        case 11:
        MIDI.sendControlChange(LoopPlayCC, 0, MIDICHAN);
        flashPin( leds[currentSwitch], pedalActiveFlash );
       
      //Toggle Display
      {
      if (Toggle[currentSwitch] == 1) {
          // Toggle on
          digitalWrite(leds[currentSwitch], HIGH);
          lcd.setCursor(0,2); lcd.print("                 ");lcd.setCursor(0,2); lcd.print("Loop PLAY ON");
          Toggle[currentSwitch] = 0;
      } else {
          // Toggle off
          digitalWrite(leds[currentSwitch], LOW);
          lcd.setCursor(0,2); lcd.print("                 ");lcd.setCursor(0,2); lcd.print("Loop PLAY OFF");
          Toggle[currentSwitch] = 1;   
        }
  }
        break;

// Switch 13.                         Loop Dub     
        case 12:
        MIDI.sendControlChange(LoopDubCC, 0, MIDICHAN);
        flashPin( leds[currentSwitch], pedalActiveFlash );
              //Toggle Display
      {
      if (Toggle[currentSwitch] == 1) {
          // Toggle on
          digitalWrite(leds[currentSwitch], HIGH);
          lcd.setCursor(0,2); lcd.print("                 ");lcd.setCursor(0,2); lcd.print("Loop DUB");
          Toggle[currentSwitch] = 0;
      } else {
          // Toggle off
          digitalWrite(leds[currentSwitch], LOW);
          lcd.setCursor(0,2); lcd.print("                 ");
          Toggle[currentSwitch] = 1;   
        }
  }       
        break;

// Switch 14.                       Loop Bypass       
        case 13:
        MIDI.sendControlChange(LoopBypassCC, 0, MIDICHAN);
        flashPin( leds[currentSwitch], pedalActiveFlash );
              //Toggle Display
      {
      if (Toggle[currentSwitch] == 1) {
          // Toggle on
          digitalWrite(leds[currentSwitch], HIGH);
          lcd.setCursor(0,2); lcd.print("                 ");lcd.setCursor(0,2); lcd.print("Loop Bypass");
          Toggle[currentSwitch] = 0;
      } else {
          // Toggle off
          digitalWrite(leds[currentSwitch], LOW);
          lcd.setCursor(0,2); lcd.print("                 ");
          Toggle[currentSwitch] = 1;   
        }
  }   
        break;

// Switch 15.                       Bank UP   
        case 14:
         if (PresetNumb>94) PresetNumb=0; else if (PresetNumb=PresetNumb+5);
         flashPin( leds[currentSwitch], pedalActiveFlash );
         lcd.clear(); lcd.setCursor(0,0); lcd.print(PresetNumb); lcd.print("-");lcd.print(PresetNumb+4);
          break;

// Switch 16.       
        case 15:

        flashPin( leds[currentSwitch], pedalActiveFlash );
        break;

// Switch 17.       
        case 16:

        flashPin( leds[currentSwitch], pedalActiveFlash );
        break;

// Switch 18.       
        case 17:

        flashPin( leds[currentSwitch], pedalActiveFlash );
        break;

// Switch 19.   
        case 18:

        flashPin( leds[currentSwitch], pedalActiveFlash );
        break;

// Switch 20.       
        case 19:

        flashPin( leds[currentSwitch], pedalActiveFlash );
        break;
       
      }
      delay( BOUNCEDELAY );
    }
    switchState[currentSwitch] = digitalRead( switches[currentSwitch] );
  }

}



//  Send a three byte midi message
void midiSend(char status, char data1, char data2) {
  Serial.write(status);
  Serial.write(data1);
  Serial.write(data2);
}

//  Send a two byte midi message
void midiProg(char status, int data ) {
  Serial.write(status);
  Serial.write(data);
}

void flashPin( int ledPin, int flashDelay ) {
  digitalWrite( ledPin, HIGH );
  delay( flashDelay );
  digitalWrite( ledPin, LOW );
}
 
First, congratulations for your ongoing work.
your layout seems very interesting for use together with the axe fx ii

I tried myself some arduino, and it is not easy at all.

If I understand well, you finally used midi 4.2 library instead of 3.2 ?
could you please describe better your LED + display
 
Thank you!

The satisfaction of having it working after many days of trial and error is huge, because few months ago I had no idea about Arduino, and now I have a controller for the Axe-FX that is working. I have learnt by borrowing and modifying code from different sources.


I am preparing more details about this project to encourage everyone to build their own foot controller. Only need to buy the components, put them together, and upload the code. I will post it later.


The controller is an Arduino Mega from Ebay:
http://www.ebay.com/itm/401036224315?_trksid=p2060353.m2749.l2649


And this is the LCD display:
http://www.ebay.com/itm/Keypad-Shie...emilanove-UNO-MEGA2560-MEGA1280-/221849044117


The switches are directly connected from ground to pins 22-24-26-28-30-32-24-…
The LED’s are connected with a 220Ohm resistor from +5V to pins 23-25-27-29-31…
(I am using even and odd numbers in order to align switches with LED’s at the Arduino Mega I/O connector. That makes it easy to test the functionality with a jump wire before connecting anything)


The midi library is version 4.2
 
Gday Piing,
Thanks for this - I may take you up on making one!

Pauly

Thank you!

The satisfaction of having it working after many days of trial and error is huge, because few months ago I had no idea about Arduino, and now I have a controller for the Axe-FX that is working. I have learnt by borrowing and modifying code from different sources.


I am preparing more details about this project to encourage everyone to build their own foot controller. Only need to buy the components, put them together, and upload the code. I will post it later.


The controller is an Arduino Mega from Ebay:
http://www.ebay.com/itm/401036224315?_trksid=p2060353.m2749.l2649


And this is the LCD display:
http://www.ebay.com/itm/Keypad-Shie...emilanove-UNO-MEGA2560-MEGA1280-/221849044117


The switches are directly connected from ground to pins 22-24-26-28-30-32-24-…
The LED’s are connected with a 220Ohm resistor from +5V to pins 23-25-27-29-31…
(I am using even and odd numbers in order to align switches with LED’s at the Arduino Mega I/O connector. That makes it easy to test the functionality with a jump wire before connecting anything)


The midi library is version 4.2
Thanks
 
Thanks for the information.
It is always interesting to read about the efforts of other people on the forum.
I agree with you. Building our own controller is very rewarding, even if it is not as powerful as the MFC-101.
 
Back
Top Bottom