I have already created a nice midi controller for another project, but want to create a much larger controller.
Having read this:
https://www.pjrc.com/teensy/td_midi.html
I want to use the 74HC4051 to multiplex a larger amount of switches and potentiometers, but am having a hard time understanding the code.
In my previous example:
Each input was assigned a note.
How will the buttons (with multiplexing) get their assigned notes?
I'm not making the connection on how to call out each button.
Any examples wold be greatly appreciated.
Having read this:
https://www.pjrc.com/teensy/td_midi.html
I want to use the 74HC4051 to multiplex a larger amount of switches and potentiometers, but am having a hard time understanding the code.
In my previous example:
Code:
/*
This is an example of the "Analog" class of the MIDI_controller library.
Connect 4 faders or potentiometers to A0-A3. These will be MIDI channel volumes of channels 1-4.
Map these in your DAW or DJ software.
If you are using a Teensy, make sure you have the USB type set to MIDI.
If you are using an Arduino Uno or Mega, use the HIDUINO firmware for the ATmega16U2.
Written by tttapa, 21/08/2015
https://github.com/tttapa/MIDI_controller
*/
#include <MIDI_controller.h> // include the library
const static byte Channel_Volume = 0x7; // controller number 7 is defined as Channel Volume in the MIDI implementation.
const static size_t analogAverage = 8; // Use the average of 8 samples to get smooth transitions and prevent noise
const static byte velocity = 127; // the maximum velocity, since MIDI uses a 7-bit number for velocity.
const static int latchTime = 3000; // the amount of time (in ms) the note is held on. Read documentation or see source code for more information.
const static byte C4 = 60; // note number 60 is defined as middle C in the MIDI implementation.
const static byte E0 = 16; // note number 60 is defined as middle C in the MIDI implementation, so 16 is E0
const byte Channel = 1; // MIDI channel 1
const byte Controller = 0x14; // MIDI controller number
const int speedMultiply = 1; // no change in speed of the encoder
//________________________________________________________________________________________________________________________________
//DigitalLatch switch1(26, E0, 1, velocity, latchTime); // Create a new member of the class 'Digital', called 'button1', on pin 2, that sends MIDI messages with note 'C4' (60) on channel 1, with velocity 127).
DigitalLatch switch2(14, E0+1, 1, velocity, latchTime);
DigitalLatch switch3(15, E0+2, 1, velocity, latchTime);
DigitalLatch switch4(16, E0+3, 1, velocity, latchTime);
Analog fader1(17, Channel_Volume, 1); // Create a new instance of the class 'Analog, called 'fader1', on pin A0, that sends MIDI messages with controller 7 (channel volume) on channel 1.
Analog fader2(18, Channel_Volume, 2);
Analog fader3(19, Channel_Volume, 3);
Analog fader4(20, Channel_Volume, 4);
Analog fader5(21, Channel_Volume, 5);
Analog fader6(22, Channel_Volume, 6);
Analog fader7(23, Channel_Volume, 7);
Digital button1(0, C4, 1, velocity); // Create a new instance of the class 'Digital', called 'button1', on pin 2, that sends MIDI messages with note 'C4' (60) on channel 1, with velocity 127).
Digital button2(1, C4+1, 1, velocity); // C4 + 1 = C#4
Digital button3(4, C4+2, 1, velocity); // C4 + 2 = D4
Digital button4(5, C4+3, 1, velocity);
Digital button5(6, C4+4, 1, velocity);
Digital button6(7, C4+5, 1, velocity);
Digital button7(8, C4+6, 1, velocity);
Digital button8(9, C4+7, 1, velocity);
Digital button9(10, C4+8, 1, velocity);
Digital button10(11, C4+9, 1, velocity);
Digital button11(12, C4+10, 1, velocity);
Digital button12(24, C4+11, 1, velocity);
Digital button13(25, C4+12, 1, velocity);
Digital button14(26, C4+13, 1, velocity);
RotaryEncoder enc(3, 2, Controller, Channel, speedMultiply, NORMAL_ENCODER, POS1_NEG127); // Create a new instance of the class 'RotaryEncoder', called 'enc', on pin 2 and 3, controller number 0x14, on channel1, no change in speed (speed is multiplied by 1), it's used as a Jog wheel, and the sign mode is set to two's complement.
//________________________________________________________________________________________________________________________________
void setup(){
USBMidiController.blink(LED_BUILTIN); // flash the built-in LED (pin 13 on most boards) on every message
USBMidiController.setDelay(15); // wait 15 ms after each message not to flood the connection
USBMidiController.begin(); // Initialise the USB MIDI connection
delay(1000); // Wait a second...
fader1.average(analogAverage); // Use the average of 8 samples to get smooth transitions and prevent noise
fader2.average(analogAverage);
fader3.average(analogAverage);
fader4.average(analogAverage);
fader5.average(analogAverage);
fader6.average(analogAverage);
fader7.average(analogAverage);
}
//________________________________________________________________________________________________________________________________
void loop(){
//switch1.refresh(); // refresh the switch (check whether the input has changed since last time, if so, send it over MIDI)
switch2.refresh();
switch3.refresh();
switch4.refresh();
fader1.refresh(); // refresh the fader (check whether the input has changed since last time, if so, send it over MIDI)
fader2.refresh();
fader3.refresh();
fader4.refresh();
fader5.refresh();
fader6.refresh();
fader7.refresh();
button1.refresh(); // refresh the button (check whether the input has changed since last time, if so, send it over MIDI)
button2.refresh();
button3.refresh();
button4.refresh();
button5.refresh();
button6.refresh();
button7.refresh();
button8.refresh();
button9.refresh();
button10.refresh();
button11.refresh();
button12.refresh();
button13.refresh();
button14.refresh();
enc.refresh();
}
Each input was assigned a note.
How will the buttons (with multiplexing) get their assigned notes?
I'm not making the connection on how to call out each button.
Any examples wold be greatly appreciated.