midi_controller

Teensy simple midi controller
git clone https://git.onna.be/midi_controller.git
Log | Files | Refs

commit 58c5556234cc8f2816dd82e2aa3fbb73bd8f79f8
parent dba9316bcccfe19efc01da6d6272e4cd76db209b
Author: Paco Esteban <paco@onna.be>
Date:   Sat, 16 Mar 2019 18:52:28 +0100

buttons logic: momentary, latch ...

Diffstat:
src/midi_controller/midi_controller.ino | 21++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/midi_controller/midi_controller.ino b/src/midi_controller/midi_controller.ino @@ -10,10 +10,14 @@ int potVal[NUM_POTS] = {0, 0, 0, 0, 0, 0, 0, 0}; int oldVal[NUM_POTS] = {0, 0, 0, 0, 0, 0, 0, 0}; #define NUM_BUTTONS 4 +#define MOMENTARY 0 +#define LATCH 1 +#define TRIGGER 2 static const uint8_t btnPins[NUM_BUTTONS] = {6, 7, 8, 9}; static const uint8_t btnCC[NUM_BUTTONS] = {11, 12, 13, 14}; uint8_t btnVal[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH}; uint8_t btnOldVal[NUM_BUTTONS] = {HIGH, HIGH, HIGH, HIGH}; +uint8_t btnMode[NUM_BUTTONS] = {MOMENTARY, TRIGGER, TRIGGER, LATCH}; Bounce *buttons = new Bounce[NUM_BUTTONS]; unsigned long previousMillis = 0; @@ -38,7 +42,6 @@ void setup() { analogReadResolution(12); analogReadAveraging(16); for (uint8_t i = 0; i < NUM_BUTTONS; ++i) { - /* pinMode(btnPins[i], INPUT_PULLUP); */ buttons[i].attach( btnPins[i] , INPUT_PULLUP ); buttons[i].interval(10); } @@ -56,14 +59,26 @@ void loop() { buttons[i].update(); if (buttons[i].fell()) { if (btnOldVal[i] == HIGH) { - // button pressed logic goes here. + // this is send max for momentary and latch usbMIDI.sendControlChange(btnCC[i], 127, MIDI_CHANNEL); btnOldVal[i] = LOW; + } else { + // if trigger mode send max again + if (btnMode[i] == TRIGGER) { + // it seems vcv rack needs notes on/off for its trigger module. + usbMIDI.sendNoteOn(btnCC[i], 127, MIDI_CHANNEL); + usbMIDI.sendNoteOff(btnCC[i], 127, MIDI_CHANNEL); + // usbMIDI.sendControlChange(btnCC[i], 127, MIDI_CHANNEL); + } else { // if we're here is latch mode, so we turn it off + usbMIDI.sendControlChange(btnCC[i], 0, MIDI_CHANNEL); + btnOldVal[i] = HIGH; + } } } if (buttons[i].rose()) { - if (btnOldVal[i] == LOW) { + if (btnOldVal[i] == LOW && btnMode[i] == MOMENTARY) { // button released logic goes here. + // we only use this for momentary buttons. usbMIDI.sendControlChange(btnCC[i], 0, MIDI_CHANNEL); btnOldVal[i] = HIGH; }