Closed nimans4 closed 3 years ago
Yeah, it'd definitely be worth throwing a simple mux example in there. I'll do that in the next update. Something like... UPDATE: This is now a working example (not the previous broken one).
#include "MIDIcontroller.h"
byte MIDIchannel = 5;
const int selector_pin_a = 0;
const int selector_pin_b = 1;
const int selector_pin_c = 2;
//const int selector_pin_d = 3; // uncomment only if using MUX-16
const int mux_input_pin = A0; // Change this to the ANALOG pin you want to use
MIDIpot* Pots[8]; // allocate space for pots
void setup(){
pinMode(selector_pin_a, OUTPUT);
pinMode(selector_pin_b, OUTPUT);
pinMode(selector_pin_c, OUTPUT);
// pinMode(selector_pin_d, OUTPUT); // only if using MUX-16
for(int i=0; i<8; i++){ // change to i<16 if using MUX-16
Pots[i] = new MIDIpot(mux_input_pin, 12+i);
// CC 12~ are probably safe to use but you can use any CC number you like.
}
}
void loop(){
for(int i=0; i<8; i++){ // change to i<16 if using MUX-16
//digitalWrite(selector_pin_d, (i&15)>>3); // uncomment only if using MUX-16
digitalWrite(selector_pin_c, (i&7)>>2);
digitalWrite(selector_pin_b, (i&3)>>1);
digitalWrite(selector_pin_a, (i&1));
Pots[i]->send();
}
// This prevents crashes that happen when incoming usbMIDI is ignored.
while(usbMIDI.read()){}
// Also uncomment this if compiling for standard MIDI
// while(MIDI.read()){}
}
The previous comment has been updated with a working example. That example has also been added to the library.
Is it possible to compliment your library to the usage of a 4051 chip?
For example the potentiometers:
You use <<MIDIpot myPot(potPin, 22);>> . But when I am using a 4051, 8 analogInputs will come via just one analog Input, due to the 4051. How will my PC Programm (Im working on a DJ Controller) distinguish between my 16 Potentiometers, so that every single potentiometer gets his own "mark"(?). Now, all Potentiometers connected to one 4051, will control all the same parameter in my PC Programm, right?