help with midi drums project

I could use some help trouble shooting my project I’ve got a basic midi project going but I can’t use digiitalWrite() when the documentation says I’m supposed to. Do I have to decode it from byte to int?

#include <MIDI.h>

#define LED 13
#define LED2 12

MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  pinMode (LED, OUTPUT);
  MIDI.begin(MIDI_CHANNEL_OMNI);

  MIDI.setHandleNoteOn(MyHandleNoteOn);
  MIDI.setHandleNoteOff(MyHandleNoteOff);
}

void loop() {
  MIDI.read();
}

void MyHandleNoteOn(byte channel, byte pitch, byte velocity) { 
  if(channel == 60){
    digitalWrite(LED,HIGH);
  }
}

void MyHandleNoteOff(byte channel, byte pitch, byte velocity) { 
  digitalWrite(LED,LOW);  //Turn LED off
}

}

MIDI_Input.ino (608 Bytes)

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.

Posting tips.

  • Always list the version of the IDE you are using and the board version if applicable.
  • How to insert an image into your post. ( Thanks Robin2 )
  • Add your sketch where applicable but please use CODE TAGS ( </> )
  • Add a SCHEMATIC were needed even if it is hand drawn
  • Add working links to any specific hardware as needed (NOT links to similar items)
  • Guessing is not the best way to describe an issue. Actual facts are the most important.
  • Remember that the people trying to help cannot see your problem so give as much information as you can

If you're talking about the digitalWrite() in MyHandleNoteOn, MIDI only has 16 channels so you're never going to see channel == 60. Perhaps that should be 'pitch' i.e. note number?

Steve

Hi I’ve already posted in the wrong topic. So I’m apologizing in advance

I could use some help trouble shooting my project I’ve got a basic midi project going but I can’t use digiitalWrite() when the documentation says I’m supposed to. Do I have to decode it from byte to int?

The code is based on “Notes and Volts”'s Tutorials

*please note this project includes two arduino nanos connected together

#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); // the led on the midi reciver arduino should light up
  MIDI.sendNoteOn(60, 40, 1);
  delay(2000);		       
  MIDI.sendNoteOff(60, 0, 1);
  digitalWrite(LED, LOW);
  delay(2000);

  digitalWrite(LED, HIGH);// the led on the midi receiver arduino should not light up
  MIDI.sendNoteOn(60, 42, 1);
  delay(2000);           
  MIDI.sendNoteOff(60, 0, 1);
  digitalWrite(LED, LOW);
  delay(2000);
}
#include <MIDI.h>

#define LED 13
#define LED2 12

MIDI_CREATE_DEFAULT_INSTANCE();

void setup() {
  pinMode (LED, OUTPUT);
  MIDI.begin(MIDI_CHANNEL_OMNI);

  MIDI.setHandleNoteOn(MyHandleNoteOn);
  MIDI.setHandleNoteOff(MyHandleNoteOff);
}

void loop() {
  MIDI.read();
}

void MyHandleNoteOn(byte channel, byte pitch, byte velocity) { 
  if(pitch == 40){ // this should work hopefully
    digitalWrite(LED,HIGH);
  }
}

void MyHandleNoteOff(byte channel, byte pitch, byte velocity) { 
  digitalWrite(LED,LOW);  //Turn LED off
}

MIDI_Input.ino (531 Bytes)

midi in sch.jpg

SCHEMATIC_Midi_Output.png

At this moment you have an answer in your other thread; starting a new thread is wasting people's time, please don't.

The only thing you have added now are some images.

If you think that there is a need to move your thread to another section, you can click the 'report to moderator' link under your post and request a move.

In your two programs you have a load of digitalWrite()s. Which one(s) do you think you can't use? And why?

Anyway one problem is definitely that you're sending a NoteOn with pitch 60, velocity 40 on channel 1. Then in your second program you're looking for a NoteOn with pitch 40. I'm glad you changed from channel to pitch as I told you last time but you still have to get the numbers right.

It is a little confusing that the parameters in the various calls are in different positions but it's all documented so you just have to pay attention.

Steve

sterretje: At this moment you have an answer in your other thread; starting a new thread is wasting people's time, please don't.

The only thing you have added now are some images.

If you think that there is a need to move your thread to another section, you can click the 'report to moderator' link under your post and request a move.

Correction! I have added images and a new piece of code which was previously unseen. I have also modified the code to fit the answers I have been given. Thank you for telling me how to move topics. This will be quite useful If I make a mistake again.

Thank you for your time

-John

Topics merged.