Code for marshall DSL 40CR 5-way momentary footswitch
#include <MIDI.h>
#include "Controller.h"
//Notes & Volts https://www.youtube.com/watch?v=PlCY_ELYAfs
//control change notes at 46:01:
// module command at 55:30:
MIDI_CREATE_DEFAULT_INSTANCE();
byte patchNum = 0;
byte cc14Num = 0;
//initialize and declare variables
int buttonPin1 =2; //push button attached to this pin
int ledPin1 =8; //classic gain GREEN led attached to this pin
int buttonPin2 =3; //push button attached to this pin
int ledPin2 =9; //classic gain RED led attached to this pin
int buttonPin3 =4; //push button attached to this pin
int ledPin3 =10; //ULTRA GAIN GREEN led attached to this pin
int buttonPin4 =5; //push button attached to this pin
int ledPin4 =11; //ULTRA GAIN RED led attached to this pin
int buttonPin5 =6; //push button attached to this pin
int ledPin5 =12; //CC 14 BLUE led attached to this pin
//this variable tracks the state of the button, low if not pressed, high if pressed
//int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
int buttonState1 = LOW;
int buttonState2 = LOW;
int buttonState3 = LOW;
int buttonState4 = LOW;
int buttonState5 = LOW;
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(2, INPUT_PULLUP) ; //Pgm Chg 0
pinMode(3, INPUT_PULLUP) ; //Pgm Chg 1
pinMode(3, INPUT_PULLUP) ; //Pgm Chg 2
pinMode(4, INPUT_PULLUP) ; //Pgm Chg 3
pinMode(5, INPUT_PULLUP) ; //Pgm Chg 4
pinMode(6, INPUT_PULLUP) ; //CC14
MIDI.begin(MIDI_CHANNEL_OMNI) ;
//led*********************************
pinMode(ledPin1, OUTPUT);// initialize the LED pin as an output:
pinMode(buttonPin1, INPUT_PULLUP);// initialize the pushbutton pin as an input:
pinMode(ledPin2, OUTPUT);// initialize the LED pin as an output:
pinMode(buttonPin2, INPUT_PULLUP);// initialize the pushbutton pin as an input:
pinMode(ledPin3, OUTPUT);// initialize the LED pin as an output:
pinMode(buttonPin3, INPUT_PULLUP);// initialize the pushbutton pin as an input:
pinMode(ledPin4, OUTPUT);// initialize the LED pin as an output:
pinMode(buttonPin4, INPUT_PULLUP);// initialize the pushbutton pin as an input:
pinMode(ledPin5, OUTPUT);// initialize the LED pin as an output:
pinMode(buttonPin5, INPUT_PULLUP);// initialize the pushbutton pin as an input:
}
void loop() {
/*double == check if this is equal to this( compare)
//this increases the patch by 1
// MIDI.sendProgramChange(22,1); //goes to patch 22, on chnl 1, this looks good
if (digitalRead(3) == LOW && patchNum < 127) {
patchNum++ ;
MIDI.sendProgramChange(patchNum,1); //goes to patchNum ++ and increases pgm by 1, on chnl 1
delay(200);
}
if (digitalRead(2) == LOW && patchNum < 1) {
patchNum-- ;
MIDI.sendProgramChange(patchNum,1); //goes to patchNum -- and decreases pgm by 1, on chnl 1
delay(200);
}
}
*/
if (digitalRead(2) == LOW) {
// patchNum++;
MIDI.sendProgramChange(0,1);
delay(200);
}
if (digitalRead(3) == LOW) {
// patchNum ;
MIDI.sendProgramChange(1,1);
delay(200);
}
if (digitalRead(4) == LOW) {
//patchNum ;
MIDI.sendProgramChange(2,1);
delay(200);
}
if (digitalRead(5) == LOW) {
//patchNum ;
MIDI.sendProgramChange(3,1);
delay(200);
}
// Control Change *****************************
if (digitalRead(6) == LOW && cc14Num < 2) {
cc14Num ++ ;
MIDI.sendControlChange(14, cc14Num, 1);
delay(400);
}
if (digitalRead(6) == LOW && cc14Num >= 1) {
cc14Num -- ;
MIDI.sendControlChange(14, cc14Num, 1);
delay(400);
}
//******************************************************
// LED 1 read the state of the pushbutton value:*****
buttonState1 = digitalRead(buttonPin1);
// check if the pushbutton is pressed.
// if it is, the Button State is HIGH:
if (buttonState1 == LOW) //toggle the LED State;
{digitalWrite(ledPin1, !digitalRead(ledPin1));
delay(250);
}
// LED 2 read the state of the pushbutton value:*****
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the Button State is HIGH:
if (buttonState2 == LOW) {
//toggle the LED State;
digitalWrite(ledPin2, !digitalRead(ledPin2));
//debounce:
delay(250);
}
// LED 3 read the state of the pushbutton value:*****
buttonState3 = digitalRead(buttonPin3);
// check if the pushbutton is pressed.
// if it is, the Button State is HIGH:
if (buttonState3 == LOW) {
//toggle the LED State;
digitalWrite(ledPin3, !digitalRead(ledPin3));
//debounce:
delay(250);
}
// LED 4 read the state of the pushbutton value:*****
buttonState4 = digitalRead(buttonPin4);
// check if the pushbutton is pressed.
// if it is, the Button State is HIGH:
if (buttonState4 == LOW) {
//toggle the LED State;
digitalWrite(ledPin4, !digitalRead(ledPin4));
//debounce:
delay(250);
//CC14 LED *******************************************
// LED 5 read the state of the pushbutton value:*****
buttonState5 = digitalRead(buttonPin5);
// check if the pushbutton is pressed.
// if it is, the Button State is HIGH:
if (buttonState5 == LOW) {
//toggle the LED State;
digitalWrite(ledPin5, !digitalRead(ledPin5));
//debounce:
delay(250);
}
}
}
//*************
/* buttonState1 = digitalRead(buttonPin1); // read current states of the pushbutton value:
buttonState2 = digitalRead(buttonPin2); // read current states of the pushbutton value:
buttonState3 = digitalRead(buttonPin3); // read current states of the pushbutton value:
buttonState4 = digitalRead(buttonPin4); // read current states of the pushbutton value:
*/
// check if the pushbutton is pressed buttonState# == HIGH/LOW
// if pressed change buttonState == HIGH to turn on ledPin#
// else if buttonState == LOW then digitalWrite(ledPin#, LOW) Keeps Led off.
/*
if (buttonState1 == LOW) { //check buttonState
digitalWrite(ledPin1, HIGH); //if HIGH turn LED on:
} else {
digitalWrite(ledPin1, LOW); // turn LED off:
}
Serial.println(buttonState1); //Print buttonState to serial
if (buttonState2 == LOW) { //check buttonState
digitalWrite(ledPin2, HIGH); //if HIGH turn LED on:
} else {
digitalWrite(ledPin2, LOW); // turn LED off:
delay(10);
}
Serial.println(buttonState2); //Print buttonState to serial
if (buttonState3 == LOW) { //check buttonState
digitalWrite(ledPin3, HIGH); //if HIGH turn LED on:
} else {
digitalWrite(ledPin3, LOW); // turn LED off:
delay(10);
Serial.println(buttonState3); //Print buttonState to serial
}
if (buttonState4 == LOW) { //check buttonState
digitalWrite(ledPin4, HIGH); //if HIGH turn LED on:
} else {
digitalWrite(ledPin4, LOW); // turn LED off:
delay(10);
Serial.println(buttonState4); //Print buttonState to serial
}
*/