Brilliant!!! it works, thanks for all your help Mike appreciate it.
Is it possible to send 2 midi commands from one button like a program change and a cc at once like button 2 will always send program message and the same cc message MidiCc(1,83,127) and MidiCc(1,83,0)?
Also would it be hard to incorporate another button into the sketch for sending Midi cc like for example,
// pin to use for indicator LED
int ledPin = 12;
// pin that is connected to the footswitch
int buttonPin = A0;
int buttonState = 0;
int buttonLastState = 0;
int buttonInitState = 0;
int muteStatus = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
// Setup serial port for MIDI communication
Serial.begin(31250);
// read current button state, a press is detected whenever
// state changes to anything else than the init state
buttonInitState = digitalRead(buttonPin);
// we only want to do something on state changes
buttonLastState = buttonInitState;
}
void loop() {
buttonState = digitalRead(buttonPin);
// has the state changed?
if (buttonState != buttonLastState) {
buttonLastState = buttonState;
if (buttonState != buttonInitState) {
// button is in pressed state, trigger action
if (muteStatus == 0) {
// mute and light up LED
digitalWrite(ledPin, HIGH);
// send CC 85 on channel 1 with value 0 to mute
// mute group 6 on a effects loop
midiCc(1, 80, 0);
muteStatus = 1;
} else {
// unmute and turn off LED
digitalWrite(ledPin, LOW);
midiCc(1, 80, 127);
muteStatus = 0;
}
}
// workaround to prevent fluttering of button state
delay(10);
}
}
void midiCc(int channel, int command, int value) {
Serial.write(175 + channel);
Serial.write(command);
Serial.write(value);
}