Skip to content

Instantly share code, notes, and snippets.

@betodealmeida
Last active April 10, 2022 23:56
Show Gist options
  • Save betodealmeida/972a550f84d9d2bd41bdfd6d7ed5b6a8 to your computer and use it in GitHub Desktop.
Save betodealmeida/972a550f84d9d2bd41bdfd6d7ed5b6a8 to your computer and use it in GitHub Desktop.

Revisions

  1. betodealmeida renamed this gist Apr 10, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. betodealmeida created this gist Apr 10, 2022.
    66 changes: 66 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    /* 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);
    }