hi Guys,
I'm working on an arduino project with an arduino pro micro, 2 buttons and an 5 pins din connector. my buttons are on pin 2 and 3, and I want to send midi via the usb port of the pro micro and via the din connector. the din connector is connected to the TX line, 5v and ground (ofcoarse with resistors).
the arduino is sending midi via the usb port to my laptop, that works. now I also want to send midi note 120 and 121 to the din connector, but that doesn't work. I've tried a different code, and that does work, so the hardware isn't the problem. this is my code:
#include <MIDIUSB.h>
#include <MIDI.h>
const int N_BUTTONS = 2;
int ButtonPin[N_BUTTONS] = { 2, 3 };
int buttonNote[N_BUTTONS] = {36, 38, };
int ButtonPortNote[N_BUTTONS] = {120, 121,};
int ButtonState[N_BUTTONS] = { 0 };
int ButtonPState[N_BUTTONS] = { 0 };
MIDI_CREATE_DEFAULT_INSTANCE();
unsigned long lastDebounceTime[N_BUTTONS] = { 0 };
unsigned long debounceTimer[N_BUTTONS] = { 0 };
int debounceDelay = 30;
int BUTTON_CH = 0;
void setup() {
Serial.begin(9600);
for (int i = 0; i < N_BUTTONS; i++) {
pinMode(ButtonPin[i], INPUT_PULLUP);
}
MIDI.begin(MIDI_CHANNEL_OFF);
}
void loop(){
for (int i = 0; i < N_BUTTONS; i++) {
ButtonState[i] = digitalRead(ButtonPin[i]);
debounceTimer[i] = millis() - lastDebounceTime[i];
if (debounceTimer[i] > debounceDelay) {
if (ButtonState[i] != ButtonPState[i]) {
lastDebounceTime[i] = millis();
if (ButtonState[i] == LOW) {
noteOn(BUTTON_CH, buttonNote[i], 127);
MIDI.sendNoteOn(ButtonPortNote[i], 127, 1);
MidiUSB.flush();
Serial.print("Button ");
Serial.print(i);
Serial.print(" ");
Serial.println("on");
} else {
noteOn(BUTTON_CH, buttonNote[i], 0);
MIDI.sendNoteOn(ButtonPortNote[i], 0, 1);
MidiUSB.flush();
Serial.print("Button ");
Serial.print(i);
Serial.print(" ");
Serial.println("off");
}
ButtonPState[i] = ButtonState[i];
}
}
}
}
//-------
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = { 0x09, 0x90 | channel, pitch, velocity };
MidiUSB.sendMIDI(noteOn);
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = { 0x0B, 0xB0 | channel, control, value };
MidiUSB.sendMIDI(event);
}
this is the code that I used to test the port:
#include <MIDI.h>
#define LED 13
MIDI_CREATE_DEFAULT_INSTANCE();
void setup()
{
pinMode(LED, OUTPUT);
MIDI.begin(MIDI_CHANNEL_OFF);
}
void loop()
{
digitalWrite(LED, HIGH);
MIDI.sendNoteOn(120, 127, 1);
delay(1000);
MIDI.sendNoteOff(120, 0, 1);
digitalWrite(LED, LOW);
delay(1000);
}
already thanks!