Hi!
I added midi to a (non midi of course) casio keyboard. It has a simple button matrix (6 rows 9 colums for 49 keys, the highest column is just for the highest key).It is not velocity sensitive.
I found the "Midi_Controller" library by tttapa to be perfect for that.
There is already an example of a matrix included, so i just adapted it, and it
works perfect.
Now i was thinking about adding velocity to the keyboard....best would be to add some kind of
Fsr underneath the keys, so velocity can be read from that (of course its "just" sensor for all keys, but that would be ok for me)
In the Matrix sketch velocity is fixed to 127, which makes total sense for buttons but i cant figure out how to change that with a variable read from a potentiometer or fsr which is connected to A0.
(i am trying it right now with a potentiometer, because i have no fsr)
Can you give me a hint?
Thanks in advance!
/*
This is an example of the "ButtonMatrix" class of the MIDI_controller library.
Connect a 6 × 9 matrix of buttons
Pull-up resistors are not necessary, because the internal ones will be used.
If you want to be able to press multiple buttons at once, add a diode
in series with each button, as shown in the schematic on the Wiki:
https://github.com/tttapa/MIDI_controller/wiki/Hardware
The note numbers are specified in the 'addresses' array.
Written by tttapa, 24/09/2017
https://github.com/tttapa/MIDI_controller
*/
#include "MIDI_Controller.h" // Include the library
const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t addresses[6][9] = { // the note numbers corresponding to the buttons in the matrix
{ 36, 42, 48, 54, 60, 66, 72, 78, 84},
{ 37, 43, 49, 55, 61, 67, 73, 79},
{ 38, 44, 50, 56, 62, 68, 74, 80},
{ 39, 45, 51, 57, 63, 69, 75, 81},
{ 40, 46, 52, 58, 64, 70, 76, 82},
{ 41, 47, 53, 59, 65, 71, 77, 83}
};
// Create a new instance of the class 'ButtonMatrix', called 'buttonmatrix', with dimensions 6 rows and 9 columns,
//that sends MIDI messages with the notes specified in 'addresses' on MIDI channel 1, with velocity 127
ButtonMatrix<6, 9> buttonmatrix({2, 3, 4, 5, 6, 7 }, {8, 9, 10, 11, 12, A2, A3, A2, A3}, addresses, velocity, 1);
void setup() {}
void loop() {
// Refresh the buttons (check whether the states have changed since last time, if so, send it over MIDI)
MIDI_Controller.refresh();
}