jb12string
Member
I'm working on a project using a Teensy 3.2. The purpose of the project is to allow a guitar player to control Ableton Live. To make it fit with the guitar players existing pedal board, we want to have 6 button and the teensy in one enclosure and 12 buttons in a second enclosure. In order to not have to find a way to connect 13 wires between enclosure 1 and 2, the plan was to use a pair of the Sparkfun 74HC4051 breakout boards, which, in my understanding, should allow me to use something like a pair of standard RJ45 jacks and a cat5e cable (3 write pins, V+, GND and 1 signal from each of the 75HC4051's, 7 total wires), There has also been discussion of adding a latching switch to enclosure 2 and have those buttons be able to send either notes or CC Messages (unless there is a way to shift the notes being sent to 12 different notes) but we haven't got to tackling that issue yet. Where I am getting hung up is on how to read the MUX. I currently have 1 hooked up with 2 buttons on it. Currently it is hooked up as Pin 21=SO, Pin 22=S1, Pin 23=S2 and the signal is routed to pin 20. The code I have I originally configured for 24 buttons, and I've been reworking it to the latest idea we've had. What I don't know is how tell teensy what MIDI note I want to send from the multiplexed buttons.
I'm a total newbie when it comes to writing code, I've tried to extrapolate what I could from the USB MIDI page and the sample of code there, but I know I'm missing something. I appreciate all the help in advance
Code:
#include <Bounce.h>
const int channel = 1;
Bounce button0 = Bounce(0, 95);
Bounce button1 = Bounce(1, 95);
Bounce button2 = Bounce(2, 95);
Bounce button3 = Bounce(3, 95);
Bounce button4 = Bounce(4, 95);
Bounce button5 = Bounce(5, 95);
Bounce button6 = Bounce(6, 95);
Bounce button7 = Bounce(7, 95);
Bounce button8 = Bounce(8, 95);
Bounce button9 = Bounce(9, 95);
Bounce button10 = Bounce(10, 95);
Bounce button11 = Bounce(11, 95);
Bounce button12 = Bounce(12, 95);
Bounce button13 = Bounce(13, 95);
Bounce button14 = Bounce(14, 95);
Bounce button15 = Bounce(15, 95);
Bounce button16 = Bounce(16, 95);
Bounce button17 = Bounce(17, 95);
Bounce button18 = Bounce(18, 95);
Bounce button19 = Bounce(19, 95);
Bounce button20 = Bounce(20, 95);
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
pinMode(17, INPUT_PULLUP);
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
pinMode(20,INPUT);
pinMode(21,OUTPUT);
pinMode(22, OUTPUT);
pinMode(23,OUTPUT);}
void loop() {
button0.update();
button1.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();
button12.update();
button13.update();
button14.update();
button15.update();
button16.update();
button17.update();
button18.update();
button19.update();
digitalWrite(21,LOW);
digitalWrite(22,LOW);
digitalWrite(23,LOW);
delayMicroseconds(50);
button20channel0.update();
digitalWrite(21,HIGH);
digitalWrite(22,LOW);
digitalWrite(23,LOW);
delayMicroseconds(50);
button2channel1.update();
if (button0.fallingEdge()) {usbMIDI.sendNoteOn(60, 99, channel);}
if (button0.risingEdge()) {usbMIDI.sendNoteOff(60, 0, channel);}
if (button1.fallingEdge()) {usbMIDI.sendNoteOn(61, 99, channel);}
if (button1.risingEdge()) {usbMIDI.sendNoteOff(61, 0, channel);}
if (button2.fallingEdge()) {usbMIDI.sendNoteOn(62, 99, channel);}
if (button2.risingEdge()) {usbMIDI.sendNoteOff(62, 0, channel);}
if (button3.fallingEdge()) {usbMIDI.sendNoteOn(63, 99, channel);}
if (button3.risingEdge()) {usbMIDI.sendNoteOff(63, 0, channel);}
if (button4.fallingEdge()) {usbMIDI.sendNoteOn(64, 99, channel);}
if (button4.risingEdge()) {usbMIDI.sendNoteOff(64, 0, channel);}
if (button5.fallingEdge()) {usbMIDI.sendNoteOn(65, 99, channel);}
if (button5.risingEdge()) {usbMIDI.sendNoteOff(65, 0, channel);}
if (button6.fallingEdge()) {usbMIDI.sendNoteOn(66, 99, channel);}
if (button6.risingEdge()) {usbMIDI.sendNoteOff(66, 0, channel);}
if (button7.fallingEdge()) {usbMIDI.sendNoteOn(67, 99, channel);}
if (button7.risingEdge()) {usbMIDI.sendNoteOff(67, 0, channel);}
if (button8.fallingEdge()) {usbMIDI.sendNoteOn(68, 99, channel);}
if (button8.risingEdge()) {usbMIDI.sendNoteOff(68, 0, channel);}
if (button9.fallingEdge()) {usbMIDI.sendNoteOn(69, 99, channel);}
if (button9.risingEdge()) {usbMIDI.sendNoteOff(69, 0, channel);}
if (button10.fallingEdge()) {usbMIDI.sendNoteOn(70, 99, channel);}
if (button10.risingEdge()) {usbMIDI.sendNoteOff(70, 0, channel);}
if (button11.fallingEdge()) {usbMIDI.sendNoteOn(71, 99, channel);}
if (button11.risingEdge()) {usbMIDI.sendNoteOff(71, 0, channel);}
if (button12.fallingEdge()) {usbMIDI.sendNoteOn(72, 99, channel);}
if (button12.risingEdge()) {usbMIDI.sendNoteOff(72, 0, channel);}
if (button13.fallingEdge()) {usbMIDI.sendNoteOn(73, 99, channel);}
if (button13.risingEdge()) {usbMIDI.sendNoteOff(73, 0, channel);}
if (button14.fallingEdge()) {usbMIDI.sendNoteOn(74, 99, channel);}
if (button14.risingEdge()) {usbMIDI.sendNoteOff(74, 0, channel);}
if (button15.fallingEdge()) {usbMIDI.sendNoteOn(75, 99, channel);}
if (button15.risingEdge()) {usbMIDI.sendNoteOff(75, 0, channel);}
if (button16.fallingEdge()) {usbMIDI.sendNoteOn(76, 99, channel);}
if (button16.risingEdge()) {usbMIDI.sendNoteOff(76, 0, channel);}
if (button17.fallingEdge()) {usbMIDI.sendNoteOn(77, 99, channel);}
if (button17.risingEdge()) {usbMIDI.sendNoteOff(77, 0, channel);}
if (button18.fallingEdge()) {usbMIDI.sendNoteOn(78, 99, channel);}
if (button18.risingEdge()) {usbMIDI.sendNoteOff(78, 0, channel);}
if (button19.fallingEdge()) {usbMIDI.sendNoteOn(79, 99, channel);}
if (button19.risingEdge()) {usbMIDI.sendNoteOff(79, 0, channel);}
if (button20channel0.fallingEdge()) {usbMIDI.sendNoteOn(80, 99, channel);}
if (button20channel0.risingEdge()) {usbMIDI.sendNoteOff(80, 0, channel);}
if (button20channel1.fallingEdge()) {usbMIDI.sendNoteOn(81, 99, channel);}
if (button20channel1.risingEdge()) {usbMIDI.sendNoteOff(81, 0, channel);}
while (usbMIDI.read()) {}
}