// midi.controller // Sends midi program change ,midi notes and control change messages based on foot pedal pressed #include // Constants #define LCD_pin 2 #define SWITCH1 3 #define SWITCH2 4 #define SWITCH3 5 #define SWITCH4 6 #define SWITCH5 7 #define SWITCH6 8 #define SWITCH7 9 #define SWITCH8 10 #define BANK_DOWN 11 #define BANK_UP 12 #define ledPin 13 // Variables: int switches[8] = {SWITCH1, SWITCH2, SWITCH3, SWITCH4, SWITCH5, SWITCH6, SWITCH7, SWITCH8 }; int switchState[8] = {HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH, HIGH }; // Initial state of switch is high due to internal pullup int currentSwitch = 0; int currentProgram = 0; // current program - sent to the output int note=0; //Midi Note (pitch) short bank=1; // (actual bank selected) int BANK_DOWNState = HIGH ; int BANK_UPState = HIGH ; int AnalogValue[6] = {0,0,0,0,0,0}; // define the "lastValue" variables int lastAnalogValue[6] = {0,0,0,0,0,0}; // select the midi Controller Number for each input int midiCCselect[6] = {1,2,3,4,5,6}; // select threshold for each analog input int thresh[6] = {1,1,1,1,1,1}; // Select the midi channel Number for each input int midichan[6]={0xB0 ,0xB0 ,0xB0 ,0xB0 ,0xB0 ,0xB0}; // select number of desired analog inputs (max 6) int input_no = 6; SoftwareSerial swSerial(LCD_pin, LCD_pin); void setup() { pinMode(LCD_pin, OUTPUT); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); // Set MIDI baud rate: Serial.begin(31250); swSerial.begin(9600); // Setup Switches pinMode(BANK_DOWN, INPUT); pinMode(BANK_UP, INPUT); for( currentSwitch = 0; currentSwitch < 8; currentSwitch++ ) { pinMode( switches[currentSwitch], INPUT ); // Set pin for switch digitalWrite( switches[currentSwitch], HIGH ); // Turn on internal pullup } } void loop() { // BANK SELECTOR start // check if the pushbutton is pressed. if(digitalRead (BANK_DOWN)==LOW) { delay(250); bank --; if (bank==0) {bank=9;} } delay(20); digitalWrite (BANK_DOWN ,HIGH); // check if the pushbutton is pressed. if (digitalRead (BANK_UP)==LOW) { delay(250); bank++; if (bank==10) {bank=1;} } delay(20); digitalWrite(BANK_UP ,HIGH); swSerial.print("?x13?y0"); swSerial.print("<"); swSerial.print("?x14?y0"); swSerial.print(bank); swSerial.print("?x15?y0"); swSerial.print(">"); for( currentSwitch = 0; currentSwitch < 8; currentSwitch++ ) { if((digitalRead(switches[currentSwitch]) != switchState[currentSwitch] )&&(switchState[currentSwitch] == HIGH)){ // bank specific action: switch (bank) { case 1: //BANK 1 DEFINITION ****************** switch( currentSwitch ) { case 0: currentProgram = 06; midiProg( 0xC0, currentProgram ); currentProgram = 51; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print("Slap Back "); swSerial.print("?x00?y0"); swSerial.print("Mesa Clean "); break; case 1: currentProgram = 05; midiProg( 0xC0, currentProgram ); currentProgram = 53; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print("Old Die "); swSerial.print("?x00?y0"); swSerial.print("Acid Vintage "); break; case 2: currentProgram = 10; midiProg( 0xC0, currentProgram ); currentProgram = 53; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print("Dirty Delay "); swSerial.print("?x00?y0"); swSerial.print("Acid Vintage "); break; case 3: note=0x01; noteOn(0x90, note, 0x45); delay(200); noteOn(0x90, note, 0x00); swSerial.print("?x00?y1"); swSerial.print(" tap "); break; case 4: currentProgram = 51; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y0"); swSerial.print("Mesa Clean "); break; case 5: currentProgram = 55; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y0"); swSerial.print("Warm "); break; case 6: currentProgram = 52; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y0"); swSerial.print("Pignose "); break; case 7: currentProgram = 40; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y0"); swSerial.print("Big Muff Pi "); break; } break; case 2: //BANK 2 DEFINITION ****************** switch( currentSwitch ) { case 0: currentProgram = 12; midiProg( 0xC0, currentProgram ); currentProgram = 55; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print("Fish Mood "); swSerial.print("?x00?y0"); swSerial.print("Warm "); break; case 1: currentProgram = 8; midiProg( 0xC0, currentProgram ); currentProgram = 55; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" Power Chord "); swSerial.print("?x00?y0"); swSerial.print("Warm "); break; case 2: currentProgram = 8; midiProg( 0xC0, currentProgram ); currentProgram = 40; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" Power Chord "); swSerial.print("?x00?y0"); swSerial.print("Big Muff Pi "); break; case 3: note=0x02; noteOn(0x90, note, 0x45); delay(200); noteOn(0x90, note, 0x00); swSerial.print("?x00?y1"); swSerial.print("FXB Mute "); break; case 4: currentProgram = 52; midiProg( 0xC1, currentProgram ); break; case 5: currentProgram = 53; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y0"); swSerial.print("Acid Vintage "); break; case 6: currentProgram = 52; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y0"); swSerial.print("Pignose "); break; case 7: currentProgram = 40; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y0"); swSerial.print("Big Muff Pi "); break; } break; case 3: //BANK 3 DEFINITION ****************** switch( currentSwitch ) { case 0: note=0x01; noteOn(0x90, note, 0x45); delay(200); noteOn(0x90, note, 0x00); swSerial.print("?x00?y1"); swSerial.print(" Record "); break; case 1: noteOn(0x90, note, 0x45); delay(200); noteOn(0x90, note, 0x00); swSerial.print("?x00?y1"); swSerial.print(" Play "); break; case 2: note=0x04; noteOn(0x90, note, 0x45); delay(200); noteOn(0x90, note, 0x00); swSerial.print("?x00?y1"); swSerial.print(" Stop "); break; case 3: note=0x02; noteOn(0x90, note, 0x45); delay(200); noteOn(0x90, note, 0x00); swSerial.print("?x00?y1"); swSerial.print("FXB Bypass "); break; case 4: currentProgram = 19; midiProg( 0xC0, currentProgram ); currentProgram = 40; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print("Diatonic Looper "); swSerial.print("?x00?y0"); swSerial.print("Big Muff Pi "); break; case 5: currentProgram = 15; midiProg( 0xC1, currentProgram ); break; case 6: note=0x04; noteOn(0x90, note, 0x45); delay(200); noteOn(0x90, note, 0x00); swSerial.print("?x00?y1"); swSerial.print(" Stop "); break; case 7: currentProgram = 15; midiProg( 0xC1, currentProgram ); break; } break; case 4: //BANK 4 DEFINITION ****************** switch( currentSwitch ) { case 0: currentProgram = 12; midiProg( 0xC0, currentProgram ); currentProgram = 55; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" "); break; case 1: currentProgram = 10; midiProg( 0xC0, currentProgram ); currentProgram = 51; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" "); break; case 2: currentProgram = 11; midiProg( 0xC0, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" "); break; case 3: currentProgram = 13; midiProg( 0xC0, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" "); break; case 4: currentProgram = 14; midiProg( 0xC1, currentProgram ); break; case 5: currentProgram = 15; midiProg( 0xC1, currentProgram ); break; case 6: currentProgram = 06; midiProg( 0xC1, currentProgram ); break; case 7: currentProgram = 15; midiProg( 0xC1, currentProgram ); break; } break; case 5: //BANK 5 DEFINITION ****************** switch( currentSwitch ) { case 0: currentProgram = 12; midiProg( 0xC0, currentProgram ); currentProgram = 55; midiProg( 0xC1, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" "); break; case 1: currentProgram = 10; midiProg( 0xC0, currentProgram ); currentProgram = 51; break; case 2: currentProgram = 11; midiProg( 0xC0, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" "); break; case 3: currentProgram = 13; midiProg( 0xC0, currentProgram ); swSerial.print("?x00?y1"); swSerial.print(" "); break; case 4: currentProgram = 14; midiProg( 0xC1, currentProgram ); break; case 5: currentProgram = 15; midiProg( 0xC1, currentProgram ); break; case 6: currentProgram = 06; midiProg( 0xC1, currentProgram ); break; case 7: currentProgram = 15; midiProg( 0xC1, currentProgram ); break; } break; case 6: //BANK 6 DEFINITION ****************** switch( currentSwitch ) { case 0: // BANK 6-action 1 break; case 1: // BANK 6-action 2 break; case 2: // BANK 6-action 3 break; case 3: // BANK 6-action 4 break; case 4: // BANK 6-action 5 break; case 5: // BANK 6-action 6 break; case 6: // BANK 6-action 7 break; case 7: // BANK 6-action 8 break; } break; case 7: //BANK 7 DEFINITION ****************** switch( currentSwitch ) { case 0: // BANK 7-action 1 break; case 1: // BANK 7-action 2 break; case 2: // BANK 7-action 3 break; case 3: // BANK 7-action 4 break; case 4: // BANK 7-action 5 break; case 5: // BANK 7-action 6 break; case 6: // BANK 7-action 7 break; case 7: // BANK 7-action 8 break; } break; case 8: //BANK 8 DEFINITION ****************** switch( currentSwitch ) { case 0: // BANK 8-action 1 break; case 1: // BANK 8-action 2 break; case 2: // BANK 8-action 3 break; case 3: // BANK 8-action 4 break; case 4: // BANK 8-action 5 break; case 5: // BANK 8-action 6 break; case 6: // BANK 8-action 7 break; case 7: // BANK 8-action 8 break; } break; case 9: //BANK 9 DEFINITION ****************** switch( currentSwitch ) { case 0: // BANK 9-action 1 break; case 1: // BANK 9-action 2 break; case 2: // BANK 9-action 3 break; case 3: // BANK 9-action 4 break; case 4: // BANK 9-action 5 break; case 5: // BANK 9-action 6 break; case 6: // BANK 9-action 7 break; case 7: // BANK 9-action 8 break; } break; } } switchState[currentSwitch] = digitalRead( switches[currentSwitch] ); } for(int i=0;i127 ) AnalogValue[i] = 127 ; //LOWER value if (AnalogValue [i] < 0) AnalogValue[i] = 0 ; { if ( AnalogValue[i] != lastAnalogValue[i] ) { //send control change on cc#i midiCC(midichan[i], midiCCselect[i], AnalogValue[i]); // update lastAnalogValue variable lastAnalogValue[i] = AnalogValue[i]; //End if } //End if } //End for } //End Loop } // Send a three byte midi message void midiSend(char status, char data1, char data2) { Serial.print(status, BYTE); Serial.print(data1, BYTE); Serial.print(data2, BYTE); } // Send a two byte midi message void midiProg(char status, int data ) { Serial.print(status, BYTE); Serial.print(data, BYTE); } // This function sends a Midi CC. void midiCC(char CC_data, char c_num, char c_val){ Serial.print(CC_data, BYTE); Serial.print(c_num, BYTE); Serial.print(c_val, BYTE); } // plays a MIDI note. Doesn't check to see that // cmd is greater than 127, or that data values are less than 127: // this function from: http://arduino.cc/en/Tutorial/Midi void noteOn(int cmd, int pitch, int velocity) { Serial.print(cmd, BYTE); Serial.print(pitch, BYTE); Serial.print(velocity, BYTE); }