need help with midi and memory

Status
Not open for further replies.

Nick1802

Well-known member
hey teensy community!!

need some help on this problem im having.

when teensy is sending midi and the program can see all the midi messages. and visa versa where the program is sending midi the teensy can see all the midi messages and print them.

but when they are both sending and reading midi im running it to problems. i think it maybe lack of memory?? im unsure. so if im moving a fader on the teensy it then transmits in midi what fader and where the fader is. dont no y but the program im using starts sending midi about what fader and where it is on the fader. in witch the teensy is then wasting time in reading ( i think this is where the problem is.

if i move the fader slowly no problems. but when i start to move the fader at a decent speed it starts to play up in not sending where the fader is now.

is there anything in this code that any1 can see is coursing this problem?

any help would me appreciated

i did have anther thread asking for help on where to start and help with this but it seems to have died.
HTML:
https://forum.pjrc.com/threads/26057-motorized-faders-via-midi-usb


Code:
#include <Bounce.h>                                //librarys to use
#include <Encoder.h>
#include <MIDI.h>
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);

//for debuging change to what you want to debug to 1 to see it in serial
char debugf = 1;        //faders and touch
char debugb = 0;        //buttons
char debuge = 0;        //encoders
char debugm = 0;        //motors

const byte touch0 = 0;                            //pin assments
const byte transmitA = 2;
const byte transmitB = 3;
const byte transmitC = 4;
const byte reciverA = 5;
const byte reciverB = 6;
const byte reciverC = 7;
const byte button0 = 14;
Encoder myEnc0(9, 8);
Encoder myEnc1(11, 10);
const byte led = 13;
const byte fader0 = 22;

char i = 0;                                        //set all valules
unsigned char fader00 = 0;
unsigned char fader01 = 0;
unsigned char fader02 = 0;
unsigned char fader03 = 0;
unsigned char fader04 = 0;
unsigned char oldfader00 = 0;
unsigned char oldfader01 = 0;
unsigned char oldfader02 = 0;
unsigned char oldfader03 = 0;
unsigned char oldfader04 = 0;
unsigned int touch00 = 0;
unsigned int touch01 = 0;
unsigned int touch02 = 0;
unsigned int touch03 = 0;
unsigned int touch04 = 0;
int newfader00 = 70;
int newfader01 = 70;
int newfader02 = 70;
int newfader03 = 70;
int newfader04 = 70;
char channelnum = 0;
char channelloc = 0;
char oldchannelloc = 0;
int newEnc0 = 0;
int newEnc1 = 0;
int old0Enc0 = -127;
int old0Enc1 = -127;
int old1Enc0 = -127;
int old1Enc1 = -127;
int CurrentTime;
int DogTimer = 0;
unsigned int touched00 = 0;
unsigned int touched01 = 0;
unsigned int touched02 = 0;
unsigned int touched03 = 0;
unsigned int touched04 = 0;
unsigned int old0touched00 = 0;
unsigned int old0touched01 = 0;
unsigned int old0touched02 = 0;
unsigned int old0touched03 = 0;
unsigned int old0touched04 = 0;
unsigned int old1touched00 = 0;
unsigned int old1touched01 = 0;
unsigned int old1touched02 = 0;
unsigned int old1touched03 = 0;
unsigned int old1touched04 = 0;
unsigned int ftouched00 = 0;
unsigned int ftouched01 = 0;
unsigned int ftouched02 = 0;
unsigned int ftouched03 = 0;
unsigned int ftouched04 = 0;

Bounce bp14r0c0 = Bounce(button0, 20);                    // add debounce to all buttons
Bounce bp14r1c0 = Bounce(button0, 20);
Bounce bp14r2c0 = Bounce(button0, 20);
Bounce bp14r3c0 = Bounce(button0, 20);
Bounce bp14r4c0 = Bounce(button0, 20);
Bounce bp14r5c0 = Bounce(button0, 20);
Bounce bp14r0c1 = Bounce(button0, 20);
Bounce bp14r1c1 = Bounce(button0, 20);
Bounce bp14r2c1 = Bounce(button0, 20);
Bounce bp14r3c1 = Bounce(button0, 20);
Bounce bp14r4c1 = Bounce(button0, 20);
Bounce bp14r0c2 = Bounce(button0, 20);
Bounce bp14r1c2 = Bounce(button0, 20);
Bounce bp14r2c2 = Bounce(button0, 20);
Bounce bp14r3c2 = Bounce(button0, 20);
Bounce bp14r4c2 = Bounce(button0, 20);
Bounce bp14r0c3 = Bounce(button0, 20);
Bounce bp14r1c3 = Bounce(button0, 20);
Bounce bp14r2c3 = Bounce(button0, 20);
Bounce bp14r3c3 = Bounce(button0, 20);

void setup() {
  if (debugf == 1 || debugb == 1 || debuge == 1 || debugm == 1) {
    Serial.begin(115200);
  }
  pwm.begin();
  pwm.setPWMFreq(1600);  // This is the maximum PWM frequency
  TWBR = 12;
  pinMode(reciverA, OUTPUT);
  pinMode(reciverB, OUTPUT);
  pinMode(reciverC, OUTPUT);
  pinMode(transmitA, OUTPUT);
  pinMode(transmitB, OUTPUT);
  pinMode(transmitC, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(button0, INPUT);
  digitalWrite(led, HIGH);
}

void loop() {
  usbMIDI.read();
  for (i = 0; i <= 63; i++) {    //loops the mux chips though a grid of 8 transmit pins and 8 reciver pins over 1 chips
    {
      digitalWrite (reciverA, (i & 1) ? HIGH : LOW);
      digitalWrite (reciverB, (i & 2) ? HIGH : LOW);
      digitalWrite (reciverC, (i & 4) ? HIGH : LOW);
      digitalWrite (transmitA, (i & 8) ? HIGH : LOW);
      digitalWrite (transmitB, (i & 16) ? HIGH : LOW);
      digitalWrite (transmitC, (i & 32) ? HIGH : LOW);
      delayMicroseconds(20);
    }

    if (i == 0) {
      bp14r0c0.update();                                    //when mux transmit and reciver are on number 0 this will update
    }
    if (i == 1) {                                           //when mux transmit and reciver are on number 1 this will update....
      bp14r1c0.update();
    }
    if (i == 2) {
      bp14r2c0.update();
    }
    if (i == 3) {
      bp14r3c0.update();
    }
    if (i == 4) {
      bp14r4c0.update();
    }
    if (i == 7) {
      fader00 = map(analogRead(fader0), 1005, 0, 0, 128);      //maps the fader resalostion to midi resalostion
      touch00 = touchRead(touch0);
    }
    if (i == 8) {
      bp14r0c1.update();
    }
    if (i == 9) {
      bp14r1c1.update();
    }
    if (i == 10) {
      bp14r2c1.update();
    }
    if (i == 11) {
      bp14r3c1.update();
    }
    if (i == 12) {
      bp14r4c1.update();
    }
    if (i == 15) {
      fader01 = map(analogRead(fader0), 1005, 0, 0, 128);
      touch01 = touchRead(touch0);
    }
    if (i == 16) {
      bp14r0c2.update();
    }
    if (i == 17) {
      bp14r1c2.update();
    }
    if (i == 18) {
      bp14r2c2.update();
    }
    if (i == 19) {
      bp14r3c2.update();
    }
    if (i == 20) {
      bp14r4c2.update();
    }
    if (i == 23) {
      fader02 = map(analogRead(fader0), 1005, 0, 0, 128);
      touch02 = touchRead(touch0);
    }
    if (i == 24) {
      bp14r0c3.update();
    }
    if (i == 25) {
      bp14r1c3.update();
    }
    if (i == 26) {
      bp14r2c3.update();
    }
    if (i == 27) {
      bp14r3c3.update();
    }
    if (i == 31) {
      fader03 = map(analogRead(fader0), 1005, 0, 0, 128);
      touch03 = touchRead(touch0);
    }
    if (i == 39) {
      fader04 = map(analogRead(fader0), 1005, 0, 0, 128);
      touch04 = touchRead(touch0);
    }
  }
  if (bp14r0c0.risingEdge()) {              //when debouce passes and detecs the button has been pushed will send midi note
    usbMIDI.sendNoteOn(0, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 0 ch 1");
    }
  }
  if (bp14r1c0.risingEdge()) {
    usbMIDI.sendNoteOn(1, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 1 ch 1");
    }
  }
  if (bp14r2c0.risingEdge()) {
    usbMIDI.sendNoteOn(2, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 2 ch 1");
    }
  }
  if (bp14r3c0.risingEdge()) {
    usbMIDI.sendNoteOn(3, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 3 ch 1");
    }
  }
  if (bp14r4c0.risingEdge()) {
    usbMIDI.sendNoteOn(4, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 4 ch 1");
    }
  }
  if (bp14r0c1.risingEdge()) {
    usbMIDI.sendNoteOn(5, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 5 ch 1");
    }
  }
  if (bp14r1c1.risingEdge()) {
    usbMIDI.sendNoteOn(6, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 6 ch 1");
    }
  }
  if (bp14r2c1.risingEdge()) {
    usbMIDI.sendNoteOn(7, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 7 ch 1");
    }
  }
  if (bp14r3c1.risingEdge()) {
    usbMIDI.sendNoteOn(8, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 8 ch 1");
    }
  }
  if (bp14r4c1.risingEdge()) {
    usbMIDI.sendNoteOn(9, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 9 ch 1");
    }
  }


  if (bp14r0c2.risingEdge()) {
    usbMIDI.sendNoteOn(10, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 10 ch 1");
    }
  }
  if (bp14r1c2.risingEdge()) {
    usbMIDI.sendNoteOn(11, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 11 ch 1");
    }
  }
  if (bp14r2c2.risingEdge()) {
    usbMIDI.sendNoteOn(12, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 12 ch 1");
    }
  }
  if (bp14r3c2.risingEdge()) {
    usbMIDI.sendNoteOn(13, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 13 ch 1");
    }
  }
  if (bp14r4c2.risingEdge()) {
    usbMIDI.sendNoteOn(14, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 14 ch 1");
    }
  }
  if (bp14r0c3.risingEdge()) {
    usbMIDI.sendNoteOn(15, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 15 ch 1");
    }
  }
  if (bp14r1c3.risingEdge()) {
    usbMIDI.sendNoteOn(16, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 16 ch 1");
    }
  }
  if (bp14r2c3.risingEdge()) {
    usbMIDI.sendNoteOn(17, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 17 ch 1");
    }
  }
  if (bp14r3c3.risingEdge()) {
    usbMIDI.sendNoteOn(18, 127, 1);
    if ( debugb == 1) {
      Serial.println("midi note 18 ch 1");
    }
  }

  if (bp14r0c0.fallingEdge()) {             //when debouce passes and detecs the button has been relesed will send midi note
    usbMIDI.sendNoteOff(0, 0, 1);
  }
  if (bp14r1c0.fallingEdge()) {
    usbMIDI.sendNoteOff(1, 0, 1);
  }
  if (bp14r2c0.fallingEdge()) {
    usbMIDI.sendNoteOff(2, 0, 1);
  }
  if (bp14r3c0.fallingEdge()) {
    usbMIDI.sendNoteOff(3, 0, 1);
  }
  if (bp14r4c0.fallingEdge()) {
    usbMIDI.sendNoteOff(4, 0, 1);
  }
  if (bp14r0c1.fallingEdge()) {
    usbMIDI.sendNoteOff(5, 0, 1);
  }
  if (bp14r1c1.fallingEdge()) {
    usbMIDI.sendNoteOff(6, 0, 1);
  }
  if (bp14r2c1.fallingEdge()) {
    usbMIDI.sendNoteOff(7, 0, 1);
  }
  if (bp14r3c1.fallingEdge()) {
    usbMIDI.sendNoteOff(8, 0, 1);
  }
  if (bp14r4c1.fallingEdge()) {
    usbMIDI.sendNoteOff(9, 0, 1);
  }
  if (bp14r0c2.fallingEdge()) {
    usbMIDI.sendNoteOff(10, 0, 1);
  }
  if (bp14r1c2.fallingEdge()) {
    usbMIDI.sendNoteOff(11, 0, 1);
  }
  if (bp14r2c2.fallingEdge()) {
    usbMIDI.sendNoteOff(12, 0, 1);
  }
  if (bp14r3c2.fallingEdge()) {
    usbMIDI.sendNoteOff(13, 0, 1);
  }
  if (bp14r4c2.fallingEdge()) {
    usbMIDI.sendNoteOff(14, 0, 1);
  }
  if (bp14r0c3.fallingEdge()) {
    usbMIDI.sendNoteOff(15, 0, 1);
  }
  if (bp14r1c3.fallingEdge()) {
    usbMIDI.sendNoteOff(16, 0, 1);
  }
  if (bp14r2c3.fallingEdge()) {
    usbMIDI.sendNoteOff(17, 0, 1);
  }
  if (bp14r3c3.fallingEdge()) {
    usbMIDI.sendNoteOff(18, 0, 1);
  }

  newEnc0 = myEnc0.read();                        //when the encoders have been rotated
  if ((newEnc0 / 4) > (old0Enc0 / 4)) {
    if ((old0Enc0 / 4) == (old1Enc0 / 4)) {
      usbMIDI.sendNoteOn(1, 127, 5);
      delayMicroseconds(5);
      usbMIDI.sendNoteOff(1, 0, 5);
      if ( debuge == 1) {
        Serial.print("ecoder0 at ");
        Serial.println(old1Enc0 / 4);
      }
    }
  }
  if ((newEnc0 / 4) < (old0Enc0 / 4)) {
    if ((old0Enc0 / 4) == (old1Enc0 / 4)) {
      usbMIDI.sendNoteOn(2, 127, 5);
      delayMicroseconds(5);
      usbMIDI.sendNoteOff(2, 0, 5);
      if ( debuge == 1) {
        Serial.print("ecoder0 at ");
        Serial.println(old1Enc0 / 4);
      }
    }
  }
  newEnc1 = myEnc1.read();
  if ((newEnc1 / 4) > (old0Enc1 / 4)) {
    if ((old0Enc1 / 4) == (old1Enc1 / 4)) {
      usbMIDI.sendNoteOn(3, 127, 5);
      delayMicroseconds(5);
      usbMIDI.sendNoteOff(3, 0, 5);
      if ( debuge == 1) {
        Serial.print("ecoder1 at ");
        Serial.println(old1Enc1 / 4);
      }
    }
  }
  if ((newEnc1 / 4) < (old0Enc1 / 4)) {
    if ((old0Enc1 / 4) == (old1Enc1 / 4)) {
      usbMIDI.sendNoteOn(4, 127, 5);
      delayMicroseconds(5);
      usbMIDI.sendNoteOff(4, 0, 5);
      if ( debuge == 1) {
        Serial.print("ecoder1 at ");
        Serial.println(old1Enc1 / 4);
      }
    }
  }
  if (touch00 < 6000) {
    touched00 = 0;
  } else {
    touched00 = 1;
  }
  if (touched00 == 1) {
    if (old0touched00 == touched00) {
      if (old1touched00 == touched00) {
        ftouched00 = 1;
      }
    }
  }
  if (touched00 == 0) {
    if (old0touched00 == touched00) {
      if (old1touched00 == touched00) {
        ftouched00 = 0;
      }
    }
  }
  if (touch01 < 6000) {
    touched01 = 0;
  } else {
    touched01 = 1;
  }
  if (touched01 == 1) {
    if (old0touched01 == touched01) {
      if (old1touched01 == touched01) {
        ftouched01 = 1;
      }
    }
  }
  if (touched01 == 0) {
    if (old0touched01 == touched01) {
      if (old1touched01 == touched01) {
        ftouched01 = 0;
      }
    }
  }
  if (touch02 < 6000) {
    touched02 = 0;
  } else {
    touched02 = 1;
  }
  if (touched02 == 1) {
    if (old0touched02 == touched02) {
      if (old1touched02 == touched02) {
        ftouched02 = 1;
      }
    }
  }
  if (touched02 == 0) {
    if (old0touched02 == touched02) {
      if (old1touched02 == touched02) {
        ftouched02 = 0;
      }
    }
  }
  if (touch03 < 6000) {
    touched03 = 0;
  } else {
    touched03 = 1;
  }
  if (touched03 == 1) {
    if (old0touched03 == touched03) {
      if (old1touched03 == touched03) {
        ftouched03 = 1;
      }
    }
  }
  if (touched03 == 0) {
    if (old0touched03 == touched03) {
      if (old1touched03 == touched03) {
        ftouched03 = 0;
      }
    }
  }
  if (touch04 < 6000) {
    touched04 = 0;
  } else {
    touched04 = 1;
  }
  if (touched04 == 1) {
    if (old0touched04 == touched04) {
      if (old1touched04 == touched04) {
        ftouched04 = 1;
      }
    }
  }
  if (touched04 == 0) {
    if (old0touched04 == touched04) {
      if (old1touched04 == touched04) {
        ftouched04 = 0;
      }
    }
  }

  old0touched00 = touched00;
  old1touched00 = old0touched00;
  old0touched01 = touched01;
  old1touched01 = old0touched01;
  old0touched02 = touched02;
  old1touched02 = old0touched02;
  old0touched03 = touched03;
  old1touched03 = old0touched03;
  old0touched04 = touched04;
  old1touched04 = old0touched04;

  if (ftouched00 == 1) {            //fader beening touched
    if (fader00 != oldfader00) {            //when fader has been moved will send midi note with volisty
      byte sysexArray[] = {0xF0, 0x7F, 0x7F, 0x02, 0x7F, 0x06, 0x00, 0x01, (fader00), (fader00), 0xF7};
      usbMIDI.sendSysEx(11, sysexArray);
      pwm.setPWM(0, 0, 0);
      pwm.setPWM(1, 0, 0);
    }
  }
  if (ftouched01 == 1) {
    if (fader01 != oldfader01) {
      usbMIDI.sendNoteOn(61, (fader01), 2);
      pwm.setPWM(2, 0, 0);
      pwm.setPWM(3, 0, 0);
    }
  }
  if (ftouched02 == 1) {
    if (fader02 != oldfader02) {
      usbMIDI.sendNoteOn(62, (fader02), 2);
      pwm.setPWM(4, 0, 0);
      pwm.setPWM(5, 0, 0);
    }
  }
  if (ftouched03 == 1) {
    if (fader03 != oldfader03) {
      usbMIDI.sendNoteOn(63, (fader03), 2);
      pwm.setPWM(6, 0, 0);
      pwm.setPWM(7, 0, 0);
    }
  }
  if (ftouched04 == 1) {
    if (fader04 != oldfader04) {
      usbMIDI.sendNoteOn(64, (fader04), 2);
      pwm.setPWM(8, 0, 0);
      pwm.setPWM(9, 0, 0);
    }
  }
  if (usbMIDI.getType() == 7 && usbMIDI.getSysExArray()[5] == 6 && oldchannelloc != usbMIDI.getSysExArray()[9]) {
    channelnum = usbMIDI.getSysExArray()[6];                    //midi systom bit for what note the consol is moving
    channelloc = usbMIDI.getSysExArray()[9];                    //midi systom bit for where the fader needs to move to
  }
  oldchannelloc = channelloc;


  if (ftouched00 == 0) {                                         //fader not touched
    if (channelnum == 0) {      //midi in to move faders
      newfader00 = channelloc;
    }
    if (newfader00 < fader00 - 1 && newfader00 > 0) {
      pwm.setPWM(0, 0, 1700);
    }
    if (newfader00 > fader00 + 1 && newfader00 < 128) {
      pwm.setPWM(1, 0, 1700);
    }
    if (newfader00 > fader00 - 1) {
      pwm.setPWM(0, 0, 0);
    }
    if (newfader00 < fader00 + 1) {
      pwm.setPWM(1, 0, 0);
    }
    if ( debugm == 1) {
      Serial.print("fader00 motor move to ");
      Serial.println(newfader00);
    }
  }
  if (ftouched01 == 0) {                                         //fader not touched
    if (channelnum == 1) {      //midi in to move faders
      newfader01 = channelloc;
    }
    if (newfader01 < fader01 - 1 && newfader01 > 0) {
      pwm.setPWM(2, 0, 1890);
    }
    if (newfader01 > fader01 + 1 && newfader01 < 128) {
      pwm.setPWM(3, 0, 1890);
    }
    if (newfader01 > fader01 - 1) {
      pwm.setPWM(2, 0, 0);
    }
    if (newfader01 < fader01 + 1) {
      pwm.setPWM(3, 0, 0);
    }
    if ( debugm == 1) {
      Serial.print("fader01 motor move to ");
      Serial.println(newfader01);
    }
  }
  if (ftouched02 == 0) {                                         //fader not touched
    if (channelnum == 2) {      //midi in to move faders
      newfader02 = channelloc;
    }
    if (newfader02 < fader02 - 1 && newfader02 > 0) {
      pwm.setPWM(4, 0, 1950);
    }
    if (newfader02 > fader02 + 1 && newfader02 < 128) {
      pwm.setPWM(5, 0, 1950);
    }
    if (newfader02 > fader02 - 1) {
      pwm.setPWM(4, 0, 0);
    }
    if (newfader02 < fader02 + 1) {
      pwm.setPWM(5, 0, 0);
    }
    if ( debugm == 1) {
      Serial.print("fader02 motor move to ");
      Serial.println(newfader02);
    }
  }  
  if (ftouched00 == 0) {              //**should be if(ftouched03 == 0){                       //fader not touched
    if (channelnum == 3) {      //midi in to move faders
      newfader03 = channelloc;
    }
    if (newfader03 < fader03 - 1 && newfader03 > 0) {
      pwm.setPWM(6, 0, 1845);
    }
    if (newfader03 > fader03 + 1 && newfader03 < 128) {
      pwm.setPWM(7, 0, 1845);
    }
    if (newfader03 > fader03 - 1) {
      pwm.setPWM(6, 0, 0);
    }
    if (newfader03 < fader03 + 1) {
      pwm.setPWM(7, 0, 0);
    }
    if ( debugm == 1) {
      Serial.print("fader03 motor move to ");
      Serial.println(newfader03);
    }
  }
  if (ftouched00 == 0) {              //**should be if(ftouched04 == 0){                                         //fader not touched
    if (channelnum == 4) {      //midi in to move faders
      newfader04 = channelloc;
    }
    if (newfader04 < fader04 - 1 && newfader04 > 0) {
      pwm.setPWM(8, 0, 3250);
    }
    if (newfader04 > fader04 + 1 && newfader04 < 128) {
      pwm.setPWM(9, 0, 3250);
    }
    if (newfader04 > fader04 - 1) {
      pwm.setPWM(8, 0, 0);
    }
    if (newfader04 < fader04 + 1) {
      pwm.setPWM(9, 0, 0);
    }
    if ( debugm == 1) {
      Serial.print("fader04 motor move to ");
      Serial.println(newfader04);
    }
  }
  if ( debugf == 1) {
    Serial.print("fader/touched/touch 0 ");
    Serial.print(fader00);
    Serial.print(" : ");
    Serial.println(ftouched00);
    Serial.println(touch00);
    Serial.print("fader/touched/touch 1 ");
    Serial.print(fader01);
    Serial.print(" : ");
    Serial.println(ftouched01);
    Serial.println(touch01);
    Serial.print("fader/touched/touch 2 ");
    Serial.print(fader02);
    Serial.print(" : ");
    Serial.println(ftouched02);
    Serial.println(touch02);
    Serial.print("fader/touched/touch 3 ");
    Serial.print(fader03);
    Serial.print(" : ");
    Serial.println(ftouched03);
    Serial.println(touch03);
    Serial.print("fader/touched/touch 4 ");
    Serial.print(fader04);
    Serial.print(" : ");
    Serial.println(ftouched04);
    Serial.println(touch04);

  }
  old1Enc0 = old0Enc0;    // this is to help the encoders from bacwords trigering
  old0Enc0 = newEnc0;
  old1Enc1 = old0Enc1;
  old0Enc1 = newEnc1;
  oldfader00 = fader00;
  oldfader01 = fader01;
  oldfader02 = fader02;
  oldfader03 = fader03;
  oldfader04 = fader04;
}
board top.jpgboard bottom.jpg
 
Perhaps the incoming MIDI messages are consuming all the available USB buffers? When that happens, your code that tries to send a message will wait for a buffer, but none ever becomes available.

Ideally, the USB code should stop accepting incoming data if only a couple buffers are left. But it's not that smart. Maybe someday it will improve, but that's probably a long way off.

If this is what's really happening, one simple fix involves repetitively calling usbMIDI.read() until it returns zero, right before you send a message. That will free up any USB buffers that are currently holding incoming MIDI messages. Then when you transmit, there will certainly be a buffer available to send your message.
 
thanks heaps Paul!!!!

adding the usbMIDI.read extra 3 times almost cleared the buffer completely so added extra 2 reads just to be sure the the buffer is cleared

again thanks heaps Paul!! and everyone else that has helped me with project.

as that was the last bug that i had found and thanks to Paul it is now fixed and i havent seen any other bugs popup when running this code.

now to go full scale!!! 15 faders 4 endless encoder wheels and over 100 buttons!!!! all on 1 lil teensy!!
 
I think that might set the record for the amount of stuff on a single Teensy-based MIDI controller. Maybe?

A lot of people have talked about connecting so much stuff. Few have actually pulled it off!
 
Status
Not open for further replies.
Back
Top