Hi guys,
Sorry in advance for this being a very basic request.
I am very stuck with my current project which is making a 24-button MIDI controller.
I have sorted the hardware side of things, however am getting very stuck with the code and whatnot.
I am using a ProMicro as it natively supports USBMIDI (have tried and failed with a Mega in the past). My design uses 24 buttons, meaning that I need more I/O pins to work with than the Pro Micro offers. I have purchased and wired up a CD74HC4067 chip, but have failed to find the right resources online to help me.
I have tried using and understanding this code, however I do not understand the channels properly and every output is always 1.
//Mux control pins
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
int en = 15;
//Mux in “SIG” pin
int SIG_pin = 0;
void setup(){
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(en, OUTPUT);
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
digitalWrite(en, LOW);
digitalWrite(SIG_pin, INPUT);
Serial.begin(9600);
}
void loop(){
//Loop through and read all 16 values
//Reports back Value at channel 6 is: 346
for(int i = 0; i < 16; i ++){
Serial.print("Value at channel ");
Serial.print(i); Serial.print("is : ");
Serial.println(readMux(i));
delay(10);
}
}
int readMux(int channel){
int controlPin[] = {s0, s1, s2, s3};
int muxChannel[16][4]={ {0,0,0,0},
{1,0,0,0},
{0,1,0,0},
{1,1,0,0},
{0,0,1,0},
{1,0,1,0},
{0,1,1,0},
{1,1,1,0},
{0,0,0,1},
{1,0,0,1},
{0,1,0,1},
{1,1,0,1},
{0,0,1,1},
{1,0,1,1},
{0,1,1,1},
{1,1,1,1} };
//loop through the 4 sig
for(int i = 0; i < 4; i ++){
digitalWrite(controlPin[i], muxChannel[channel][i]);
}
//read the value at the SIG pin
int val = digitalRead(SIG_pin); //return the value
return val;
}
The diagram below is for demonstrating my system and how I have the multiplexer connected, just ignore the pin numbers as I have changed them in my code to suit my project.
Any help would be much appreciated, could someone also point me to a page where someone explains multiplexing properly as I feel like I still don't understand it fully.
Many thanks.