Midi

Status
Not open for further replies.

Medbring

New member
Hi I'm trying to get in to Teensy 4.0 with a simple project.

By midi notes I would like to make a digitalWrite to specifics pins if it's a MIDI send G, E, and so one. If I'm using the code i can get it to work with key down. But how do i select a specific note?

I think that i could do something like

void setup() {
if(note=60){
pinMode(ledPin, OUTPUT);
usbMIDI.setHandleNoteOff(OnNoteOff);
usbMIDI.setHandleNoteOn(OnNoteOn) ;
digitalWrite(ledPin, HIGH);
delay(400); // Blink LED once at startup
digitalWrite(ledPin, LOW);
}
}


Code from tutorial.

// USB MIDI receive example, Note on/off -> LED on/off
// contributed by Alessandro Fasan

int ledPin = 13;

void OnNoteOn(byte channel, byte note, byte velocity) {
digitalWrite(ledPin, HIGH); // Any Note-On turns on LED
}

void OnNoteOff(byte channel, byte note, byte velocity) {
digitalWrite(ledPin, LOW); // Any Note-Off turns off LED
}

void setup() {
pinMode(ledPin, OUTPUT);
usbMIDI.setHandleNoteOff(OnNoteOff);
usbMIDI.setHandleNoteOn(OnNoteOn) ;
digitalWrite(ledPin, HIGH);
delay(400); // Blink LED once at startup
digitalWrite(ledPin, LOW);
}

void loop() {
usbMIDI.read();
}
 
You could do something like this:
Code:
void myNoteOn(byte channel, byte note, byte velocity) {
  if (note = 35) {
    digitalWrite(ledPin, HIGH); // Note 35 turns on onboard LED
  }
}

void myNoteOff(byte channel, byte note, byte velocity) {
  if (note > 35) {
    digitalWrite(ledPin, LOW);  // Note 35 turns off oboard LED
  }
}

Paul
 
Thanks a lot.

As I understand it, only pin 13 should be activated when a C4 is sent (note60) But no matter which note I send, it is activated.

Any ideas for what I'm doing wrong?

Code:
int ledPin = 13;

void OnNoteOn(byte channel, byte note, byte velocity) {
  if (note = 60) {
    digitalWrite(ledPin, HIGH); // Note 60 turns on onboard LED
  }
}

void OnNoteOff(byte channel, byte note, byte velocity) {
    if (note > 60) {
    digitalWrite(ledPin, LOW);  // Note 60 turns off oboard LED
  }
}

void setup() {
  pinMode(ledPin, OUTPUT);
  usbMIDI.setHandleNoteOff(OnNoteOff);
  usbMIDI.setHandleNoteOn(OnNoteOn) ;
  digitalWrite(ledPin, HIGH);
  delay(400);                 // Blink LED once at startup
  digitalWrite(ledPin, LOW);
}

void loop() {
  usbMIDI.read();
}
 
It's working now! Thanks a lot.

Code:
void OnNoteOn(byte channel, byte note, byte velocity) {
  if (note == 60) {
    digitalWrite(ledPin, HIGH); // Note 60 turns on onboard LED
  }
}
 
Status
Not open for further replies.
Back
Top