If everything goes right I intend to have a very portable electronic piano accordion with 32 treble keys and 72 (!!!!) Stradella bass keys. The ESP32 board I am using has 32 free pins, potentially less, as there are always some limitations for these ports.

So, I need a matrix (or 2) to multiplex those buttons and use fewer pins.
Therefore, I can have a matrix of 4x8 for the treble keyboard (32 keys) and another matrix of 8x9 for the Stradella bass (72) buttons.
4 + 8 + 8 + 9 = 29 pins! Maybe it is feasible, maybe it is not and I will need an actual multiplexer or use 2 ESP32 boards? Who knows? I will eventually find that out.
It would be something like this, from the brilliant Rafael Corvino, a fellow Brazilian like me (https://www.instagram.com/corvino_acordeonmidi).

But it is not a MIDI accordion, it would not need a computer to generate the sounds.
Anyway, I don't have the Melodica yet (yes, it will be my keyboard) nor the buttons for the bass, I will start small, a 2x2 matrix with diodes to prevent ghosting, this video explains it brilliantly:
This is my little prototype, it looks silly but it was hard for me to get there, I made this mistake https://www.reddit.com/r/ElectronicsRepair/comments/103pfk8/im_building_a_keyboard_matrix_with_a_micro/ but now it is okay!

I only have 4 buttons for now (still waiting for the Temu order to get here :)
This very simple program shows the buttons states, you can press them all at once, neat!
#include <Arduino.h>
#include <Keypad.h>
const byte ROWS = 2;
const byte COLS = 2;
char keys[ROWS][COLS] = {
{'1','2'},
{'3','4'}
};
byte rowPins[ROWS] = {22, 23};
byte colPins[COLS] = {25, 26};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
unsigned long loopCount;
unsigned long startTime;
String msg;
void setup() {
Serial.begin(9600);
loopCount = 0;
startTime = millis();
msg = "";
}
void loop() {
loopCount++;
if ((millis() - startTime) > 5000) {
Serial.print("Average loops per second = ");
Serial.println(loopCount/5);
startTime = millis();
loopCount = 0;
}
// Fills keypad.key[] array with up-to 10 active keys.
// Returns true if there are ANY active keys.
if (keypad.getKeys()) {
for (int i = 0; i < LIST_MAX; i++) { // Scan the whole key list.
if (keypad.key[i].stateChanged) { // Only find keys that have changed state.
switch (keypad.key[i].kstate) { // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
case PRESSED:
msg = " PRESSED.";
break;
case HOLD:
msg = " HOLD.";
break;
case RELEASED:
msg = " RELEASED.";
break;
case IDLE:
msg = " IDLE.";
}
Serial.print("Key ");
Serial.print(keypad.key[i].kchar);
Serial.println(msg);
}
}
}
} // End loop
Bruno Campidelli
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.