Skip to content

Instantly share code, notes, and snippets.

@betodealmeida
Last active April 10, 2022 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save betodealmeida/972a550f84d9d2bd41bdfd6d7ed5b6a8 to your computer and use it in GitHub Desktop.
Save betodealmeida/972a550f84d9d2bd41bdfd6d7ed5b6a8 to your computer and use it in GitHub Desktop.
/* A MIDI pedal for the Critter & Guitari Organelle.
*
* An expression pedal sends CC numbers 21-24, depending on
* the switch pressed. A sustain pedal sends CC 25 to control
* the Aux button.
*/
#include <Bounce.h>
const int midiChannel = 15;
const int expressionCC[] = {21, 22, 23, 24};
const int sustainCC = 25;
const int sustainPin = 15;
Bounce sustainPedal = Bounce(sustainPin, 10); // 10 ms debounce
int activeKnob = 0;
int i, pinNumber;
int previousExpressionValue = -1;
void setup() {
pinMode(sustainPin, INPUT_PULLUP);
// set pullup in switches
for (pinNumber = 5; pinNumber < 9; pinNumber++) {
pinMode(pinNumber, INPUT_PULLUP);
}
// set LED pins as outputs
for (pinNumber = 9; pinNumber < 13; pinNumber++) {
pinMode(pinNumber, OUTPUT);
}
}
void loop() {
for (i = 0; i < 4; i++) {
// read switches
if (digitalRead(5 + i) == LOW) {
activeKnob = i;
}
// turn active knob LED on
digitalWrite(9 + i, activeKnob == i ? HIGH : LOW);
}
// read expression pedal
int expressionValue = analogRead(A0) / 8;
if (expressionValue != previousExpressionValue) {
usbMIDI.sendControlChange(expressionCC[activeKnob], expressionValue, midiChannel);
previousExpressionValue = expressionValue;
}
// read sustain pedal
if (sustainPedal.update()) {
// signal goes HIGH when pedal is pressed
if (sustainPedal.risingEdge()) {
usbMIDI.sendControlChange(sustainCC, 127, midiChannel);
} else if (sustainPedal.fallingEdge()) {
usbMIDI.sendControlChange(sustainCC, 0, midiChannel);
}
}
// discard incoming MIDI messages
while (usbMIDI.read()) {}
delay(5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment