i want to use both recieve and send midi msg ( arduino 2560 pro and my synth) .
i tried. when only (midi out from arduino to synth) is connected . working well.button are sending Prog change messeges.
but when both (midi in and out ) are connected. i am getting a flood of midi messeges (NoteOn/NoteOff/Prog Change etc. randomly) into my synthesizer.with pressing any key of synth.
my midi in connection are in this way
my first simple try code is below to see note messege data on oled display
#include <MIDI.h>
#include <Keypad.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
const byte ROWS = 15;
const byte COLS = 10;
char keys[ROWS][COLS] = {
{1,2,3,4,5,6,7,8,9,10},
{11,12,13,14,15,16,17,18,19,20},
{21,22,23,24,25,26,27,28,29,30},
{31,32,33,34,35,36,37,38,39,40},
{41,42,43,44,45,46,47,48,49,50},
{51,52,53,54,55,56,57,58,59,60},
{61,62,63,64,65,66,67,68,69,70},
{71,72,73,74,75,76,77,78,79,80},
{81,82,83,84,85,86,87,88,89,90},
{91,92,93,94,95,96,97,98,99,100},
{101,102,103,104,105,106,107,108,109,110},
{111,112,113,114,115,116,117,118,119,120},
{121,122,123,124,125,126,127,128,129,130},
{131,132,133,134,135,136,137,138,139,140},
{141,142,143,144,145,146,147,148,149,150}
};
byte rowPins[ROWS] = {4,5,6,7,8,9,10,11,12,14,15,16,17,22,23};
byte colPins[COLS] = {32,33,34,35,36,37,38,39,40,41};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
String msg;
MIDI_CREATE_DEFAULT_INSTANCE();
byte sysexArray[8] = {0xF0,0x7F,0x7F,0x04,0x04,0x00,50,0xF7};
int Shift1 = 0;
in Note_In = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
MIDI.begin(4);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.display();
display.clearDisplay();
msg = "";
}
void SCN (int gg) {
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0,0); // Start at top-left corner
display.println(gg);
display.setCursor(50,0); // Start at top-left corner
display.println(msg);
display.setCursor(0,16); // Start at top-left corner
display.println(analogRead(A0));
display.display();
}
void loop() {
if (kpd.getKeys())
{
for (int i=0; i<LIST_MAX; i++)
{ int mykey = kpd.key[i].kchar;
if (( kpd.key[i].stateChanged ) && (mykey < 128 )&& (mykey > 0 ))
{
switch (kpd.key[i].kstate) {
case PRESSED:
msg = " PRESSED."; SCN (mykey); MIDI.sendProgramChange(mykey, 1);
break;
case RELEASED:
msg = " RELEASED."; SCN (mykey);
break;
}
}
// ----------------------------------------------------------------------------------------------
}
}
if (MIDI.read()) // Is there a MIDI message incoming ?
{
switch(MIDI.getType()) // Get the type of the message we caught
{ case midi::NoteOn: // If it is a Note on,
int Channel = (MIDI.getChannel());
int D1 = ( MIDI.getData1()) ;
int D2 = ( MIDI.getData2());
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0,0);
display.println(Channel);
display.setCursor(50,0);
display.println(D1);
display.setCursor(0,16);
display.println(D2);
display.display();
Note_In = D1;
break;
}
}
} // End loop
please take a look . what mistake is being done by me in MIDI incoming code section???
