Hello, I apologize immediately for my poor English, but in English there is much more information about MIDI.
Well I have this problem / question using the libraries "MIDIUSB.h" and "Keypad.h"
When compiling, I get this error:::
*C:\Users\Roberto\Documents\Arduino\PRO MICRO\Piano_Midi_promicro_v17-07-2022\Piano_Midi_promicro_v17-07-2022.ino: In function 'void noteOn(byte, byte, byte)':*
*C:\Users\Roberto\Documents\Arduino\PRO MICRO\Piano_Midi_promicro_v17-07-2022\Piano_Midi_promicro_v17-07-2022.ino:6:42: warning: narrowing conversion of '(int)(144 | ((unsigned char)((int)channel)))' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]*
* midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};*
* ~~~~~^~~~~~~~~*
*C:\Users\Roberto\Documents\Arduino\PRO MICRO\Piano_Midi_promicro_v17-07-2022\Piano_Midi_promicro_v17-07-2022.ino: In function 'void noteOff(byte, byte, byte)':*
*C:\Users\Roberto\Documents\Arduino\PRO MICRO\Piano_Midi_promicro_v17-07-2022\Piano_Midi_promicro_v17-07-2022.ino:11:43: warning: narrowing conversion of '(int)(128 | ((unsigned char)((int)channel)))' from 'int' to 'uint8_t {aka unsigned char}' inside { } [-Wnarrowing]*
* midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};*
I would like to correct it but this is beyond my newbie knowledge.
I understand that there are problems converting data from (char) to (int).
please help
here I leave the code
#include "MIDIUSB.h"
#include <Keypad.h>
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
const byte ROWS = 6;
const byte COLS = 2;
byte keys[ROWS][COLS] = {
{60,66},
{61,67},
{62,68},
{63,69},
{64,70},
{65,71}
};
byte rowPins[ROWS] = {7, 6, 5, 4, 3, 2};
byte colPins[COLS] = {16, 10};
byte Channel = 0;
byte velocity =80;
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
Serial.begin(115200);
}
void loop() {
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++)
{
if ( kpd.key[i].stateChanged )
{
switch (kpd.key[i].kstate) {
case PRESSED:
noteOn(Channel, int(kpd.key[i].kchar), velocity);
MidiUSB.flush();
break;
case RELEASED:
noteOff(Channel, int(kpd.key[i].kchar), velocity);
MidiUSB.flush();
break;
}
}
}
}
}