Last active
April 10, 2022 23:56
-
-
Save betodealmeida/972a550f84d9d2bd41bdfd6d7ed5b6a8 to your computer and use it in GitHub Desktop.
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
/* 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