andrewslobford
Member
Hi everyone!
I'm working on a project right now and I need a bunch of analog inputs added to my Teensy LC and then I need it to output Midi signals (its a midi controller)
In the end I'll eventually need about 15 potentiometers and I'm trying to connect them all to my Teensy LC using this CD74HC4051 breakout board:
CD74HC4051 (multiplexer breakout board)
TEENSY LC (coolest little dude)
I've been searching for days (seriously dozens of hours at this point) and found like dozens of other threads and tutorials on almost the exact same matter and all the threads and tutorials I've read through are dead ends (either questions never get answered, or the OP never follows up with complete code or status of project or the tutorial is for Arduino only..here's some examples..
https://forum.pjrc.com/threads/2879...ultiplexer-with-MIDI?highlight=multiplex+midi
https://forum.pjrc.com/threads/4535...h-insane-number-of-sensors?highlight=74HC4051
https://forum.pjrc.com/threads/26057-motorized-faders-via-midi-usb?highlight=74HC4051
https://forum.pjrc.com/threads/31797-Teensy-FSR-based-MIDI-controller?highlight=74HC4051
https://forum.pjrc.com/threads/35221-DIY-MIDI-74HC4051-74HCT4051-Question?highlight=74HC4051
https://forum.pjrc.com/threads/3424...ler-with-16-Potentiometers?highlight=74HC4051
http://www.instructables.com/id/Sugarcube-MIDI-Controller/
https://www.youtube.com/watch?v=DXhxdsGREsU&t=621s
https://www.youtube.com/watch?v=NmxoBdEJG28
Anyways I just wanna get this over with and I never want anyone else to have to do this much digging. It's driving me insane at this point because I'm not a programmer at all, nor am I the brightest bulb in the bag of bulbs.....that being said I'm determined to get this done!
I've boiled my problem down to ONE potentiometer attached to the multiplexer then to the Teensy LC to eliminate confusion.
GOAL:
I've stitched together code from different parts of different tutorials that didn't work at all but made some sense and miraculously my code kinda works!
When I plug in the Teensy, Midi note 4A registers right where it should on the channel I want it to. Right now it seems to be increasing it and decreasing it a gazillion times a second regardless of weather or not I'm turning the Pot...when I do turn the pot it seems to change the value up and down franticly a gazillion times a second too..
Here is the diagram of my project.
Here is my code. It doesnt seem to work properly but If anyone here can help me get it to work then I promise that I'll follow up and update this thread with the final working code for the greater good....I should note that this is the first code I've ever written and have no clue what most of it means but I understand the logic behind it I guess.
I'm crossing my fingers and just hoping some good Samaritan will lend a hand because I seriously have no business coding anything...
edit: changed a number
I'm working on a project right now and I need a bunch of analog inputs added to my Teensy LC and then I need it to output Midi signals (its a midi controller)
In the end I'll eventually need about 15 potentiometers and I'm trying to connect them all to my Teensy LC using this CD74HC4051 breakout board:
CD74HC4051 (multiplexer breakout board)
TEENSY LC (coolest little dude)
I've been searching for days (seriously dozens of hours at this point) and found like dozens of other threads and tutorials on almost the exact same matter and all the threads and tutorials I've read through are dead ends (either questions never get answered, or the OP never follows up with complete code or status of project or the tutorial is for Arduino only..here's some examples..
https://forum.pjrc.com/threads/2879...ultiplexer-with-MIDI?highlight=multiplex+midi
https://forum.pjrc.com/threads/4535...h-insane-number-of-sensors?highlight=74HC4051
https://forum.pjrc.com/threads/26057-motorized-faders-via-midi-usb?highlight=74HC4051
https://forum.pjrc.com/threads/31797-Teensy-FSR-based-MIDI-controller?highlight=74HC4051
https://forum.pjrc.com/threads/35221-DIY-MIDI-74HC4051-74HCT4051-Question?highlight=74HC4051
https://forum.pjrc.com/threads/3424...ler-with-16-Potentiometers?highlight=74HC4051
http://www.instructables.com/id/Sugarcube-MIDI-Controller/
https://www.youtube.com/watch?v=DXhxdsGREsU&t=621s
https://www.youtube.com/watch?v=NmxoBdEJG28
Anyways I just wanna get this over with and I never want anyone else to have to do this much digging. It's driving me insane at this point because I'm not a programmer at all, nor am I the brightest bulb in the bag of bulbs.....that being said I'm determined to get this done!
I've boiled my problem down to ONE potentiometer attached to the multiplexer then to the Teensy LC to eliminate confusion.
GOAL:
- The pot should control MIDI cc 74 (also known as 4A in hex) on MIDI channel 1.
- When the pot is turned clockwise/counter-clockwise the MIDI Data2 value should increase/decrease
- When the pot is not being turned I want that Data2 value to just stay where it was turned to....
I've stitched together code from different parts of different tutorials that didn't work at all but made some sense and miraculously my code kinda works!
When I plug in the Teensy, Midi note 4A registers right where it should on the channel I want it to. Right now it seems to be increasing it and decreasing it a gazillion times a second regardless of weather or not I'm turning the Pot...when I do turn the pot it seems to change the value up and down franticly a gazillion times a second too..
Here is the diagram of my project.
Here is my code. It doesnt seem to work properly but If anyone here can help me get it to work then I promise that I'll follow up and update this thread with the final working code for the greater good....I should note that this is the first code I've ever written and have no clue what most of it means but I understand the logic behind it I guess.
/* USB MIDI AnalogControlChange Example
You must select MIDI from the "Tools > USB Type" menu
http://www.pjrc.com/teensy/td_midi.html
This example code is in the public domain.
*/
#include <Bounce.h>
//mapping of mux to teensy digital pins
int pin_Out_S0 = 0;
int pin_Out_S1 = 1;
int pin_Out_S2 = 2;
int pin_Out_S3 = 3;
int pin_In_Mux1 = A0;
//the state of the mux channels(initialized to zero)
int Mux1_State[16] = {0};
// the MIDI channel number to send messages
const int channel = 1;
// the MIDI continuous controller for each analog input
const int controllerA0 = 74; // 74 = test cc74
void setup() {
pinMode(pin_Out_S0, OUTPUT);
pinMode(pin_Out_S1, OUTPUT);
pinMode(pin_Out_S2, OUTPUT);
pinMode(pin_Out_S3, OUTPUT);
Serial.begin(9600);
}
// store previously sent values, to detect changes
int previousA0 = -1;
elapsedMillis msec = 0;
void loop() {
//mux code
{
updateMux1();
for(int i = 0; i < 16; i ++) {
if(i == 15) {
Serial.println(Mux1_State);
} else {
Serial.print(Mux1_State);
Serial.print(",");
}
}
}
// only check the analog inputs 50 times per second,
// to prevent a flood of MIDI messages
if (msec >= 20) {
msec = 0;
int n0 = analogRead(A0) / 16;
// only transmit MIDI messages if analog input changed
if (n0 != previousA0) {
usbMIDI.sendControlChange(controllerA0, n0, channel);
previousA0 = n0;
}
}
// MIDI Controllers should discard incoming MIDI messages.
// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
while (usbMIDI.read()) {
// ignore incoming messages
}
}
void updateMux1 () {
for (int i = 0; i < 16; i++){
digitalWrite(pin_Out_S0, HIGH && (i & B00000001));
digitalWrite(pin_Out_S1, HIGH && (i & B00000010));
digitalWrite(pin_Out_S2, HIGH && (i & B00000100));
digitalWrite(pin_Out_S3, HIGH && (i & B00001000));
Mux1_State = analogRead(pin_In_Mux1);
}
}
I'm crossing my fingers and just hoping some good Samaritan will lend a hand because I seriously have no business coding anything...
edit: changed a number
Last edited: