Midi Channel recieve

Status
Not open for further replies.
Hi, I'm working on a project to transmit midi to control some dc motors. I have successfully been able to do this which is great. The problem I'm having is the teensy is receiving all midi channels and I won't the teensy to only receive one midi channel at a time, ie. channel 16 only. What do I need to add to the code to be able to do this. Here is the sketch I'm using

// use PWM pins 3, 4, 6, 9, 10
int pins[] = {3, 4, 6, 9, 10};
#define numNotes 5

// motor channel 0 will be triggered by lowNote
// motor channel 1 will be triggered by lowNote + 1 etc.
int lowNote = 60; // MIDI note 60 (C-2) // change to use different note triggers

// Teensy MIDI callbacks
void OnNoteOn(byte channel, byte note, byte velocity);
void OnNoteOff(byte channel, byte note, byte velocity);

// initialization
void setup() {
// output pins
for (int i = 0; i < 5; i++) {
pinMode(pins, OUTPUT);
}

// init MIDI callbacks
usbMIDI.setHandleNoteOn(OnNoteOn);
usbMIDI.setHandleNoteOff(OnNoteOff);
}

// main loop
void loop() {
while (usbMIDI.read()) {
}

// nothing to do here...

}

// OnNoteOn() callback
// When a new "note on" message is recieved
void OnNoteOn(byte channel, byte note, byte velocity) {

// check if the note is in range for our possible motor outputs
if (note >= lowNote && note < lowNote + numNotes) {
// adjust for note # offset
int notePin = note - lowNote;
// linear map from MIDI's 7 bits of resolution to Teensy's 12
analogWrite(pins[notePin], velocity << 5 );
}

}

// OnNoteOff() callback
// When a new "note off" message is received
void OnNoteOff(byte channel, byte note, byte velocity) {

// check that it is in the range
if (note >= lowNote && note < lowNote + numNotes) {
int notePin = note - lowNote; // offset
analogWrite(pins[notePin], 0); // turn it off
}
}
 
maybe like this?

Code:
void OnNoteOn(byte channel, byte note, byte velocity) {
  if (channel == 1) {
    OnNoteOnChannel1(not, velocity);
  } else if (channel == 2) {
    OnNoteOnChannel2(not, velocity);
  } else if (channel == 3) {
    //etc...
  }
}

void OnNoteOnChannel1(byte note, byte velocity) {
  // only for channel #1
}

void OnNoteOnChannel2(byte note, byte velocity) {
  // only for channel #2
}
 
maybe like this?

Code:
void OnNoteOn(byte channel, byte note, byte velocity) {
  if (channel == 1) {
    OnNoteOnChannel1(not, velocity);
  } else if (channel == 2) {
    OnNoteOnChannel2(not, velocity);
  } else if (channel == 3) {
    //etc...
  }
}

void OnNoteOnChannel1(byte note, byte velocity) {
  // only for channel #1
}

void OnNoteOnChannel2(byte note, byte velocity) {
  // only for channel #2
}

Hey thanks for the reply,
Im a total newbie with this stuff.
Im just wondering where I put these changes
Thanks
 
Code:
// main loop
 void loop() {
 while (usbMIDI.read()) {
 }

 // nothing to do here...

 }
But his code doesn't actually do anything.... perhaps Paul has teased the actual question from OP. I can't make sense of it yet. But I believe he means send for receive.
 
Status
Not open for further replies.
Back
Top