I'm currently trying to do a code for a 4x4 matrix to do a launchpad and a MIDI controller in one console, I figured out the first half for my analog inputs (pots and sliders) but I can't seem to find the right logic for the matrix. I bought a CD74HC4067 mux to connect all my push buttons, when compiling and uploading my code to the Teensy 4.1 and opening FL Studio the notes react to the push button press but instead of sending one single note it sends bombs of the same note until I release the button. Right now my code only includes 4 buttons I want to figure out why it does this before adding the rest. If anyone is willing help or give tips with my logic I would very much appreciate it
const int channel = 0;
const int s0 = 1; //address pins
const int s1 = 2; //address pins
const int s2 = 3; //address pins
const int s3 = 4; //address pins
int b0 = 0; //button values
int b1 = 0; //button values
int b2 = 0; //button values
int b3 = 0; //button values
void setup() {
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, INPUT_PULLUP);
}
void loop() {
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(50);
b0 = digitalRead(5);
if (b0 == LOW) {
usbMIDI.sendNoteOn(60, 99, 0);
}
////////////////////////////////////////////////////
digitalWrite(s0, HIGH);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(50);
button1.update();
b1 = digitalRead(5);
if (b1 == LOW) {
usbMIDI.sendNoteOn(61, 99, 0);
}
////////////////////////////////////////////////////
digitalWrite(s0, LOW);
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(50);
button2.update();
b2 = digitalRead(5);
if (b2 == LOW) {
usbMIDI.sendNoteOn(62, 99, 0);
}
////////////////////////////////////////////////////
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(50);
button3.update();
b3 = digitalRead(5);
if (b3 == LOW) {
usbMIDI.sendNoteOn(63, 99, 0);
}
while (usbMIDI.read()) {
}
}
const int channel = 0;
const int s0 = 1; //address pins
const int s1 = 2; //address pins
const int s2 = 3; //address pins
const int s3 = 4; //address pins
int b0 = 0; //button values
int b1 = 0; //button values
int b2 = 0; //button values
int b3 = 0; //button values
void setup() {
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, INPUT_PULLUP);
}
void loop() {
digitalWrite(s0, LOW);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(50);
b0 = digitalRead(5);
if (b0 == LOW) {
usbMIDI.sendNoteOn(60, 99, 0);
}
////////////////////////////////////////////////////
digitalWrite(s0, HIGH);
digitalWrite(s1, LOW);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(50);
button1.update();
b1 = digitalRead(5);
if (b1 == LOW) {
usbMIDI.sendNoteOn(61, 99, 0);
}
////////////////////////////////////////////////////
digitalWrite(s0, LOW);
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(50);
button2.update();
b2 = digitalRead(5);
if (b2 == LOW) {
usbMIDI.sendNoteOn(62, 99, 0);
}
////////////////////////////////////////////////////
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
delayMicroseconds(50);
button3.update();
b3 = digitalRead(5);
if (b3 == LOW) {
usbMIDI.sendNoteOn(63, 99, 0);
}
while (usbMIDI.read()) {
}
}