-
-
Save peterdikant/59af17e9ffad0504ea62 to your computer and use it in GitHub Desktop.
Latching version of arduino footswitch script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ledPin = 12; | |
// pin that is connected to the footswitch | |
int buttonPin = 2; | |
int buttonState = 0; | |
int buttonLastState = 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 | |
buttonLastState = digitalRead(buttonPin); | |
} | |
void loop() { | |
buttonState = digitalRead(buttonPin); | |
// has the state changed? | |
if (buttonState != buttonLastState) { | |
if (buttonState == HIGH) { | |
// mute and light up LED | |
digitalWrite(ledPin, HIGH); | |
// send CC 85 on channel 2 with value 0 to mute | |
// mute group 6 on a Behringer X32 | |
midiCc(2, 85, 0); | |
} else { | |
// unmute and turn off LED | |
digitalWrite(ledPin, LOW); | |
midiCc(2, 85, 127); | |
} | |
buttonLastState = buttonState; | |
// 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment