Teensy 3 Cant Do Note on/off with Bounce

Status
Not open for further replies.

daz1761

Member
I'm just trying to write a sketch in order to send a note on/off message. I've copied the code from the example. I just seem to get a random note appear now and then when using a simple max object.

Code:
#include <Bounce.h>  // Bounce library makes button change detection easy

#define kMidiChannel 1
#define kMidiControl 1

Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time

void setup() {
  
  pinMode(1, INPUT_PULLUP);
  
}

void loop() {
  
  int val = analogRead(14);
  val = map(val, 0, 1023, 0, 127);
  
  usbMIDI.sendControlChange(kMidiControl, val, kMidiChannel);
    
  button1.update();
  
   // Note On messages when each button is pressed
  if (button1.fallingEdge()) {
    usbMIDI.sendNoteOn(60, 99, kMidiChannel);  // 60 = C4
  }
  
  // Note Off messages when each button is released
  if (button1.risingEdge()) {
    usbMIDI.sendNoteOff(60, 0, kMidiChannel);  // 60 = C4
  }
}

Also, does the Bounce library use interrupts? Its just I thought if you want a MIDI message to take precedence you would need an interrupt?

Edit: After taking away the CC send command, the problem went away which leads me to ask, how can I transmit CC messages and note messages at the same time efficiently?
 
Last edited:
Status
Not open for further replies.
Back
Top