Hey guys!
This is my first post, i doesnt really know anything about the rules here, so im sorry if i cross any of them.
I have an old keyboard, and i want to modify it to send midi to my pc via usb.
I heard about flashing the firmware on the arduino, but thats not an option for me since i want to use it for many other projects, and i dont want to do flash it every time.
Heres my code:
#define LED 13 // LED pin on Arduino board
#define switch1 2 // 1st Switch
#define MIDI_COMMAND_CONTROL_CHANGE 0xB0
#define MIDI_COMMAND_NOTE_ON B10010000
#define MIDI_COMMAND_NOTE_OFF B10000000
//Variables
int switch1LastState = 0;
int switch1CurrentState = 0;
// the format of the message to send Via serial
typedef union {
struct {
uint8_t command;
uint8_t channel;
uint8_t data2;
//uint8_t data3;
} msg;
uint8_t raw[3];
} t_midiMsg;
void setup() {
pinMode(LED, OUTPUT);
pinMode(switch1,INPUT);
Serial.begin(115000);
}
void loop() {
t_midiMsg midiMsg1; // MIDI message for Switch 1
switch1CurrentState = digitalRead(switch1);
if (switch1CurrentState == 1){
if(switch1LastState == 0){
midiMsg1.msg.command = MIDI_COMMAND_NOTE_ON ;
midiMsg1.msg.channel = 0x3D;
midiMsg1.msg.data2 = 0x79;
//midiMsg1.msg.data3 = 0x30;
//Serial.write(midiMsg1.raw, sizeof(midiMsg1));
Serial.write(midiMsg1.raw,sizeof(midiMsg1));
switch1LastState = 1;
}
}
if (switch1CurrentState == 0){
if(switch1LastState == 1){
midiMsg1.msg.command = MIDI_COMMAND_NOTE_OFF;
midiMsg1.msg.channel = 0x10;
midiMsg1.msg.data2 = 0x20;
//midiMsg1.msg.data3 = 0x30;
Serial.write(midiMsg1.raw, sizeof(midiMsg1));
switch1LastState = 0;
}
}
}
I started this tutorial : https://sites.google.com/site/bharatbhushankonka/home/diy-midi-over-usb-using-arduino-uno
His t_midiusb union uses 4 bytes, and it works, but as i checked with midi-ox hes wrong with the names,
data3 is lost in the communication, and only the first 3 bytes is used. I readd various descriptions on midi, and all of them said that the standard midi messege is 3 bytes long.Like this one Midi Messages
So i deleted the 4th byte, and now it doesnt works and i dont know why.
But thats not my biggest problem.
The problem is, that the note off doesnt shows up, however the arduino sends the right messege
for example 80 10 20 , or 80 10 20 30, but theres no note off in midi-ox, and i dont know why.
Is there anyone who can help me?
Sorry for my bad english.