//extend Keypad class
#include <Keypad.h>
//initialize rows and columns
const byte ROWS = 4;
const byte COLS = 4;
//define the symbols on the buttons
char hexaKeys[ROWS][COLS] = {
{'0','1','2','3'},
{'4','5','6','7'},
{'8','9','A','B'},
{'C','D','E','F'}
};
//row pinouts
byte rowPins[ROWS] = {5, 4, 3, 2};
//column pinouts
byte colPins[COLS] = {9, 8, 7, 6};
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
int MIDInotes[16] = {60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83, 84, 86};
//SOME METHODS:
//MIDI noteON
void noteOn(int channel, int pitch, int velocity) {
Serial.write(channel);
Serial.write(pitch);
Serial.write(velocity);
delay(1);
}
void setup() {
Serial.begin(31250);
}
void loop() {
char customKey = customKeypad.getKey();
if (customKey){
char testChar = customKey;
int someInt;
if (testChar >= 'A' && testChar <= 'F')
{
someInt = 10 + (int)(testChar- 'A');
}
else
{
someInt = (int)(customKey - '0');
}
for (int i = 0; i < 16; i++)
{
if (i == someInt)
{
noteOn(144,MIDInotes[someInt], 127);
}
else
{
noteOn(144, MIDInotes[i], 0);
}
delay(1);
}
noteOn(144, MIDInotes[someInt], 127);
delay(100);
}