Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 26 to 50 of 51

Thread: motorized faders via midi usb

  1. #26
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    Quote Originally Posted by Nick1802 View Post
    hey is anyone reading anything i post???

    i have a strange problem with my teensy!!
    As as first check (forgive me if this is a little beneath you) make sure you are blockwriting 0's to your variables at startup. Assigning a variable does not blockwrite to the memory space and if you read it before it has actually been populated (by an interrupt method for example) you might well get jibber jabber.

    I couldn't possibly count the number of times i've been "bamboozled" by variables / memory space which i am otherwise convinced will have been populated before i read it.

  2. #27
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    thanks pensive, but nothing about the teensy is beneath me, we are always learning!
    but i do not no what blockwriting is :S

  3. #28
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    Sorry, just initialise all your variable arrays to a starting value (usually 0) so the memory is written to .

    Assigning variables doesn't write anything to the memory so it might contain 1s, 0s and/or combinations.

    The quick way to do this is a "Block write" to the whole ram segment which is how it would be done in Assembler. But for your purposes set every variable you use to a starting value of some reasonable kind.

  4. #29
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,082
    You need to add pullup or pulldown resistors on pins 20 and 21, so the voltage on those pins is well defined when the buttons are not pressed. Without resistors, the voltage on the pin is pretty much random, because the pins are unconnected. The rapid changes from nearby signals can capacitively couple to the pins, causing their voltage to change. Resistors to establish a known voltage in the connected circumstance will solve this problem.

    Also, add a brief delay between changing the 3 control signals and actually reading the voltage. delayMicroseconds(20) is probably plenty. Those 74HC4051 chips have resistance in their switches, which takes a little while to charge/discharge any capacitance on the pins after you change the control signals.

  5. #30
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    You need to add pullup or pulldown resistors on pins 20 and 21

    d'oh!!!! i knew i forgot something else from the schematic. i have 10k resisters (resistor)--(button)--(button)--(button)--(4051)--(teensy)

    i never even thought of putting it between the teensy and the 4051.

  6. #31
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    so untill now i hadn't connected anything to A7 on the 4051's and for some reason that i cant see in the code when im using the serial print in the loop not in the setup of the code posted earlyer its returning the readings on A7. as well as any button that i hit

    @ Pensive.
    every thing i think i have tried for block write havent worked.
    would u be able to point me in the right direction? web page or something that will teach me how to do this or a example?

  7. #32
    Senior Member Pensive's Avatar
    Join Date
    Aug 2014
    Location
    Basingstoke, UK
    Posts
    562
    Don't worry

    I've checked your code it's not likely to be the problem.

    You've done this for your global variables:
    Int v=0;

    By setting them to 0 on declare you have achieved the goal.

    I did notice a redundant Col integer in your function, but apart from that I can't see anything more than needs doing in that regard.

    Rgds

    Jon

  8. #33
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey guys!
    so i changed some of the code so that the buttons work as digital (finerly got it working(dont no what i was doing wrong)) and the faders still work at analog.

    Code:
    #include <Encoder.h>
    
    const byte sensor0 = 14;
    const byte sensor1 = 15;
    const byte fader0 = A8;
    const byte transmitA = 2;
    const byte transmitB = 3;
    const byte transmitC = 4;
    const byte reciverA = 5;
    const byte reciverB = 6;
    const byte reciverC = 7;
    Encoder myEnc0 (8,9);
    int v = 0;
    int w = 0;
    int led = 13;
    
    void setup() {
      Serial.begin(115200);
      pinMode(reciverA,OUTPUT);
      pinMode(reciverB,OUTPUT);
      pinMode(reciverC,OUTPUT);
      pinMode(transmitA,OUTPUT);
      pinMode(transmitB,OUTPUT);
      pinMode(transmitC,OUTPUT);
      pinMode(sensor0,INPUT);
      pinMode(sensor1,INPUT);
      pinMode(fader0,INPUT);
      pinMode(led,OUTPUT);
      digitalWrite (led,HIGH);
    }
    long oldEnc0 = -999;
    
    int readKeyboard() {
      int j,i,code;
      code=0;
      for(i=0;i<=7;i++) {
        for(j=0;j<=7;j++) {
          code++;
          //col
          {
            digitalWrite (transmitA, (i & 1) ? HIGH : LOW);
            digitalWrite (transmitB, (i & 2) ? HIGH : LOW);
            digitalWrite (transmitC, (i & 4) ? HIGH : LOW);
          }
          //row
          {
            digitalWrite (reciverA, (j & 1) ? HIGH : LOW);
            digitalWrite (reciverB, (j & 2) ? HIGH : LOW);
            digitalWrite (reciverC, (j & 4) ? HIGH : LOW);
            digitalRead(sensor0);
            digitalRead(sensor1);
          }
          //delay(0);
    
          // Read the actual Value
          v = digitalRead(sensor0);
          w = digitalRead(sensor1);
          /*
    Serial.print("Col: ");
           Serial.print(i);
           Serial.print(",Row: ");
           Serial.print(j);
           Serial.print("),IC1: ");
           Serial.print(v);
           Serial.print(" ,IC2: ");
           Serial.println(w);
           */
          if(v==HIGH)
          {
            return code;
          }
          if(w==HIGH) 
          {
            return (code+64);
          }
        }
      }
    }
    int readSensor (const byte i)
    {
      // select correct MUX channel
      digitalWrite (transmitA, (i & 1) ? HIGH : LOW);
      digitalWrite (transmitB, (i & 2) ? HIGH : LOW);
      digitalWrite (transmitC, (i & 4) ? HIGH : LOW);
      // now read the sensor
      return analogRead (fader0);
    }
    
    void loop(){
      {
        v = readKeyboard();
        if(v>=1)
          Serial.println(v);
        //delay(100);
      }
      {
        long newEnc0;
        newEnc0= myEnc0.read();
        if (newEnc0 != oldEnc0) {
          Serial.print("Enc0 = ");
          Serial.println(newEnc0/4);
          oldEnc0 = newEnc0;
        }
      }
      {
        // show all 8 sensor readings
        for (byte i = 0; i <=7; i++)
        {
          Serial.print ("fader ");
          Serial.print (i);
          Serial.print (" reads: ");
          Serial.println (readSensor (i)/4);
          //delay (50);
        }
      }
    }
    but i have spent all week reading up on how to do usbmidi but i cant work it out how to do it with the matrix of buttons.

    can any1 help?

    thanks

  9. #34
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey guys i really am stuck trying to work out how to get the usbmidi to work with the matrix of buttons!!!

    can any1 point me in the right direction or do maybe button 25 with the code i posted earlier?

  10. #35
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    the only way i can think of getting it to work is maybe this way
    Code:
      // select 74HC4051 channel 5 (of 0 to 7)
      digitalWrite(1, HIGH);
      digitalWrite(2, LOW);
      digitalWrite(3, HIGH);
      
      // allow 50 us for signals to stablize
      delayMicroseconds(50);
      
      // read the signals routed to pins 10, 19, 20
      // through channel 5 of each 74HC4051 chip
      buttonPin10channel5.update();
      knobPin19channel5 = analogRead(19);
      knobPin20channel5 = analogRead(20);
    that i keep coming to at the end of the usbmidi info page.
    only thing is that i would have to right this out 64 times just for a 8x8 with the 4051 but there has to be a easyer way that im not seeing

    any help would be fanatic!!!

  11. #36
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    ok so i have sorta worked out the usb midi for the buttons.



    Code:
    #include <Encoder.h>
    #include <Bounce.h>
    
    const byte sensor0 = 14;
    const byte sensor1 = 15;
    const byte fader0 = A8;
    const byte touch0 = 0;
    const byte transmitA = 2;
    const byte transmitB = 3;
    const byte transmitC = 4;
    const byte reciverA = 5;
    const byte reciverB = 6;
    const byte reciverC = 7;
    Encoder myEnc0 (8,9);
    const int motorDown = 18;
    const int motorUp = 19;
    int led = 13;
    int v = 0;
    int w = 0;
    int t[8] = {0};
    int f[8] = {0};
    double faderMax = 1023;
    double faderMin = 1;
    volatile bool touched = false;
    
    void setup() {
      Serial.begin(115200);
      pinMode(reciverA,OUTPUT);
      pinMode(reciverB,OUTPUT);
      pinMode(reciverC,OUTPUT);
      pinMode(transmitA,OUTPUT);
      pinMode(transmitB,OUTPUT);
      pinMode(transmitC,OUTPUT);
      pinMode(sensor0,INPUT);
      pinMode(sensor1,INPUT);
      pinMode(fader0,INPUT);
      pinMode(touch0,INPUT);
      pinMode(led,OUTPUT);
      pinMode(motorUp,OUTPUT);
      pinMode(motorDown,OUTPUT);
      digitalWrite (led,HIGH);
    }
    long oldEnc0 = -999;
    
    int readKeyboard() {
      int j,i,code;
      code=0;
      for(i=0;i<=7;i++) {
        for(j=0;j<=7;j++) {
          code++;
          //col
          {
            digitalWrite (transmitA, (i & 1) ? HIGH : LOW);
            digitalWrite (transmitB, (i & 2) ? HIGH : LOW);
            digitalWrite (transmitC, (i & 4) ? HIGH : LOW);
          }
          //row
          {
            digitalWrite (reciverA, (j & 1) ? HIGH : LOW);
            digitalWrite (reciverB, (j & 2) ? HIGH : LOW);
            digitalWrite (reciverC, (j & 4) ? HIGH : LOW);
            delayMicroseconds(20);
            digitalRead(sensor0);
            digitalRead(sensor1);
          }
          
    
          // Read the actual Value
          v = digitalRead(sensor0);
          w = digitalRead(sensor1);
          /*
    Serial.print("Col: ");
           Serial.print(i);
           Serial.print(",Row: ");
           Serial.print(j);
           Serial.print("),IC1: ");
           Serial.print(v);
           Serial.print(" ,IC2: ");
           Serial.println(w);
           */
          if(v==HIGH)
          {return code;}
          if(w==HIGH) 
          {return (code+64);}
        }
      }
    }
    
    int readfader0 (const byte i)
    {
    {
      // select correct MUX channel
      digitalWrite (transmitA, (i & 1) ? HIGH : LOW);
      digitalWrite (transmitB, (i & 2) ? HIGH : LOW);
      digitalWrite (transmitC, (i & 4) ? HIGH : LOW);
      // now read the sensor
      return analogRead (fader0);
      }
      f[i] = analogRead (fader0);
    }
    
    int readtouch0 (const byte i)
    {
    {
      // select correct MUX channel
      digitalWrite (transmitA, (i & 1) ? HIGH : LOW);
      digitalWrite (transmitB, (i & 2) ? HIGH : LOW);
      digitalWrite (transmitC, (i & 4) ? HIGH : LOW);
      // now read the sensor
      return touchRead (touch0);
    }
    t[i] = touchRead (touch0);
    }
    void loop(){
    
      {
        v = readKeyboard();
        if(v >= 1 && v <= 128){
          Serial.println(v);
          if (v.fallingEdge()) {                      **********************************
        usbMIDI.sendNoteOn(v-1, 127, 1);
      }
      if (v.risingEdge()){                            **********************************
        usbMIDI.sendNoteOff(v-1, 0, 1);
      }
    }
    if (v >= 129 && v <= 254){
       Serial.println(v);
       if (v.fallingEdge()) {                         **********************************
        usbMIDI.sendNoteOn(v-1, 127, 2);
      }
      if (v.risingEdge()){                            **********************************
        usbMIDI.sendNoteOff(v-1, 0, 2);
      }}
    }
      {
        long newEnc0;
        newEnc0= myEnc0.read();
        if (newEnc0 != oldEnc0) {
          Serial.print("Enc0 = ");
          Serial.println(newEnc0/4);
          oldEnc0 = newEnc0;
        }
      }
      {
        // show all 8 sensor readings
        for (byte i = 0; i <=7; i++)
        {
          if(readfader0(i)>2){
          Serial.print ("fader ");
          Serial.print (i);
          Serial.print (" reads: ");
          Serial.println (readfader0(i));
          }
          if (readtouch0(i) > 3600){
            Serial.print("touch0 ");
            Serial.print(i);
            Serial.println(" is touched");
    }
    }
    }
    }
    i keep getting errors with the lines that are ******************************

    error that i keep getting are
    error: request for member 'fallingEdge' in 'v', which is of non-class type 'int'
    error: request for member 'risingEdge' in 'v', which is of non-class type 'int'
    error: request for member 'fallingEdge' in 'v', which is of non-class type 'int'
    error: request for member 'risingEdge' in 'v', which is of non-class type 'int'




    when i changed this bit of code
    Code:
    void loop(){
    
      {
        v = readKeyboard();
        if(v >= 1 && v <= 128){
          Serial.println(v);
          if (v.fallingEdge()) {
        usbMIDI.sendNoteOn(v-1, 127, 1);
      }
      if (v.risingEdge()){
        usbMIDI.sendNoteOff(v-1, 0, 1);
      }
    }
    if (v >= 129 && v <= 254){
       Serial.println(v);
       if (v.fallingEdge()) {
        usbMIDI.sendNoteOn(v-1, 127, 2);
      }
      if (v.risingEdge()){
        usbMIDI.sendNoteOff(v-1, 0, 2);
      }}
    }

    to be like this

    Code:
    void loop(){
    
      {
        v = readKeyboard();
        if(v >= 1 && v <= 128){
          Serial.println(v);
        usbMIDI.sendNoteOn(v-1, 127, 1);
      }
    if (v >= 129 && v <= 254){
       Serial.println(v);
        usbMIDI.sendNoteOn(v-1, 127, 2);
    }
    }

    it works but with out the note off when i let go. but i cant work out how to add it with out errors

    i had also tryed useing the bounce lib but couldnt work it out ether but im not sure if i even need it when useing mux

  12. #37
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey all,
    got buttons done with help from Nantonos

    Code:
    #include <Bounce.h>
    
    const byte sensor0 = 14;
    const byte sensor1 = 15;
    const byte transmitA = 2;
    const byte transmitB = 3;
    const byte transmitC = 4;
    const byte reciverA = 5;
    const byte reciverB = 6;
    const byte reciverC = 7;
    int i = 0;
    int led = 13;
    Bounce bp14r0c0 = Bounce(sensor0,20);
    Bounce bp14r3c0 = Bounce(sensor0,20);
    Bounce bp14r7c0 = Bounce(sensor0,20);
    Bounce bp15r0c7 = Bounce(sensor1,20);
    Bounce bp15r3c7 = Bounce(sensor1,20);
    Bounce bp15r7c7 = Bounce(sensor1,20);
    
    void setup() {
      Serial.begin(115200);
      pinMode(reciverA,OUTPUT);
      pinMode(reciverB,OUTPUT);
      pinMode(reciverC,OUTPUT);
      pinMode(transmitA,OUTPUT);
      pinMode(transmitB,OUTPUT);
      pinMode(transmitC,OUTPUT);
      pinMode(sensor0,INPUT);
      pinMode(sensor1,INPUT);
      pinMode(led, OUTPUT);
      digitalWrite (led, HIGH);
    }
    
    void loop(){
      for(i=0;i<=63;i++) {
        //col
        {
          digitalWrite (transmitA, (i & 1) ? HIGH : LOW);
          digitalWrite (transmitB, (i & 2) ? HIGH : LOW);
          digitalWrite (transmitC, (i & 4) ? HIGH : LOW);
          digitalWrite (reciverA, (i & 8) ? HIGH : LOW);
          digitalWrite (reciverB, (i & 16) ? HIGH : LOW);
          digitalWrite (reciverC, (i & 32) ? HIGH : LOW);
          delayMicroseconds(20);
          if (i==0){
            bp14r0c0.update();
          }
          if (i==3){
            bp14r3c0.update();
          }
          if (i==7){
            bp14r7c0.update();
          }
          if (i==56){
            bp15r0c7.update();
          }
          if (i==59){
            bp15r3c7.update();
          }
          if (i==63){
            bp15r7c7.update();
          }
        }
      }
    
      if (bp14r0c0.risingEdge()) {
        usbMIDI.sendNoteOn(0, 127, 1);  // 60 = C4
      }
      if (bp14r3c0.risingEdge()) {
        usbMIDI.sendNoteOn(1, 127, 1);  // 61 = C#4
      }
      if (bp14r7c0.risingEdge()) {
        usbMIDI.sendNoteOn(2, 127, 1);  // 62 = D4
      }
      if (bp15r0c7.risingEdge()) {
        usbMIDI.sendNoteOn(125, 127, 1);  // 60 = C4
      }
      if (bp15r3c7.risingEdge()) {
        usbMIDI.sendNoteOn(126, 127, 1);  // 61 = C#4
      }
      if (bp15r7c7.risingEdge()) {
        usbMIDI.sendNoteOn(127, 127, 1);  // 62 = D4
      }
    
      // Note Off messages when each button is released
      if (bp14r0c0.fallingEdge()) {
        usbMIDI.sendNoteOff(0, 0, 1);  // 60 = C4
      }
      if (bp14r3c0.fallingEdge()) {
        usbMIDI.sendNoteOff(1, 0, 1);  // 61 = C#4
      }
      if (bp14r7c0.fallingEdge()) {
        usbMIDI.sendNoteOff(2, 0, 1);  // 62 = D4
      }
      if (bp15r0c7.fallingEdge()) {
        usbMIDI.sendNoteOff(125, 0, 1);  // 60 = C4
      }
      if (bp15r3c7.fallingEdge()) {
        usbMIDI.sendNoteOff(126, 0, 1);  // 61 = C#4
      }
      if (bp15r7c7.fallingEdge()) {
        usbMIDI.sendNoteOff(127, 0, 1);  // 62 = D4
      }
    
      // MIDI Controllers should discard incoming MIDI messages.
      while (usbMIDI.read()) {
      }
    }

  13. #38
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    s now i am working on the encoders. I have it working and out putting to midi but im having trouble with it going back and forth when only turning it 1 way.

    Code:
    #include <Encoder.h>
    
    Encoder myEnc0 (9,8);
    int led = 13;
    
    
    void setup() {
      Serial.begin(115200);
      pinMode(led, OUTPUT);
      pinMode(led, HIGH);
    }
    long oldEnc0 = -999;
    
    
    void loop(){
      long newEnc0;
      newEnc0= myEnc0.read();
      if((newEnc0/4) > (oldEnc0/4)){
        usbMIDI.sendNoteOn(1,127,5);
        delayMicroseconds(5);
        usbMIDI.sendNoteOff(1,0,5);
      }
      if ((newEnc0/4) < (oldEnc0/4)){
        usbMIDI.sendNoteOn(2,127,5);
        delayMicroseconds(5);
        usbMIDI.sendNoteOff(2,0,5);
      }
      oldEnc0 = newEnc0;
    }
    the following is when i turn the encoder clock-wise

    Code:
     000EB52A   1  --     94    02    7F    5  D -1 Note On   
     000EB52A   1  --     84    02    00    5  D -1 Note Off  
     000EB54F   1  --     94    02    7F    5  D -1 Note On   
     000EB550   1  --     84    02    00    5  D -1 Note Off  
     000EB566   1  --     94    02    7F    5  D -1 Note On   
     000EB574   1  --     84    02    00    5  D -1 Note Off  
     000EB82B   1  --     94    02    7F    5  D -1 Note On   
     000EB830   1  --     84    02    00    5  D -1 Note Off  
     000EB830   1  --     94    01    7F    5  C#-1 Note On         
     000EB830   1  --     84    01    00    5  C#-1 Note Off  
     000EB832   1  --     94    02    7F    5  D -1 Note On   
     000EB832   1  --     84    02    00    5  D -1 Note Off  
     000EB848   1  --     94    02    7F    5  D -1 Note On   
     000EB84C   1  --     84    02    00    5  D -1 Note Off  
     000EB862   1  --     94    02    7F    5  D -1 Note On   
     000EB86B   1  --     84    02    00    5  D -1 Note Off  
     000EB8BF   1  --     94    02    7F    5  D -1 Note On   
     000EB8C2   1  --     84    02    00    5  D -1 Note Off  
     000EB8C2   1  --     94    01    7F    5  C#-1 Note On   
     000EB8C2   1  --     84    01    00    5  C#-1 Note Off  
     000EB8C4   1  --     94    02    7F    5  D -1 Note On   
     000EB8C4   1  --     84    02    00    5  D -1 Note Off  
     000EB8C4   1  --     94    01    7F    5  C#-1 Note On   
     000EB8C6   1  --     84    01    00    5  C#-1 Note Off  
     000EB8C6   1  --     94    02    7F    5  D -1 Note On   
     000EB8C6   1  --     84    02    00    5  D -1 Note Off

  14. #39
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey all,
    i added some lines of code that sorta fixed the problem i am having with the encoder to midi
    Code:
     
    void loop(){
    long newEnc0;
      newEnc0= myEnc0.read();
      if((newEnc0/4) > (old0Enc0/4)){
        if ((old0Enc0/4) == (old1Enc0/4)){
          usbMIDI.sendNoteOn(1,127,5);
          delayMicroseconds(5);
          usbMIDI.sendNoteOff(1,0,5);
        }
      }
      if ((newEnc0/4) < (old0Enc0/4)){
        if ((old0Enc0/4) == (old1Enc0/4)){
          usbMIDI.sendNoteOn(2,127,5);
          delayMicroseconds(5);
          usbMIDI.sendNoteOff(2,0,5);
        }
      }
      old1Enc0 = old0Enc0;
      old0Enc0 = newEnc0;
    }
    its working a lil better still has a lil bounce every now and then.
    help on that would still be helpful!

    next problem im having that im clueless about how to fix at the moment is the following code, when i move fader 2, fader 1 is ment to follow. when the code and breadboard is setup with out the mux this works fine. with the mux not so much when i move fader 2, fader 1 will start moveing in the right direction but doesnt stop goes all the way to the end and keeps trying till i pull the power to it.

    Code:
    const byte fader0 = 22;
    
    const byte transmitA = 2;
    const byte transmitB = 3;
    const byte transmitC = 4;
    int i = 0;
    int led = 13;
    int fader01;
    int fader02;
    const int motorDown = 19;
    const int motorUp = 18;
    double faderMax = 1024;
    double faderMin = 0;
    
    void setup() {
      Serial.begin(115200);
      pinMode(transmitA,OUTPUT);
      pinMode(transmitB,OUTPUT);
      pinMode(transmitC,OUTPUT);
      pinMode(fader0,INPUT);
      pinMode(led, OUTPUT);
      pinMode(motorUp, OUTPUT);
      pinMode(motorDown, OUTPUT);
      digitalWrite (led, HIGH);
    }
    
    void loop(){
      for(i=0;i<=7;i++) {
        //col
        {
          digitalWrite (transmitA, (i & 1) ? HIGH : LOW);
          digitalWrite (transmitB, (i & 2) ? HIGH : LOW);
          digitalWrite (transmitC, (i & 4) ? HIGH : LOW);
          delayMicroseconds(20);
          if(i==0){
            fader01 = analogRead(fader0);
          }
          if (i==1){
            fader02 = analogRead(fader0);
          }
        }
      }
    
      if (fader02 < fader01 - 100 && fader02 > faderMin) {
        digitalWrite(motorDown, HIGH);
        while (fader02 < fader01 - 100) {};  //Loops until motor is done moving
        digitalWrite(motorDown, LOW);
      }
      else if (fader02 > fader01 + 100 && fader02 < faderMax) {
        digitalWrite(motorUp, HIGH);
        while (fader02 > fader01 + 100) {}; //Loops until motor is done moving
        digitalWrite(motorUp, LOW);
      }
    }
    plz help

  15. #40
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey everyone, update on progress of how this is going.

    i fixed the last issue i was having with the code getting stuck in a loop that wasn't updating witch was y the motor never stopped.

    and i had fried my i2c chips pca9635 when soldering it onto a breakout board. seance gotten the adafruit 9685 witch has its own lib making life easier!!

    Code:
    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>
    
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
    
    
    const byte fader0 = 22;
    
    const byte transmitA = 2;
    const byte transmitB = 3;
    const byte transmitC = 4;
    int i = 0;
    int led = 13;
    int fader01;
    int fader02;
    double faderMax = 1014;
    double faderMin = 10;
    
    
    void setup() {
      Serial.begin(115200);
      pinMode(transmitA,OUTPUT);
      pinMode(transmitB,OUTPUT);
      pinMode(transmitC,OUTPUT);
      pinMode(fader0,INPUT);
      pinMode(led, OUTPUT);
      digitalWrite (led, HIGH);
      pwm.begin();
      pwm.setPWMFreq(1600);  // This is the maximum PWM frequency
      uint8_t twbrbackup = TWBR;
      TWBR = 12; 
    }
    
    void loop(){
      for(i=0;i<=7;i++) {
        //col
        {
          digitalWrite (transmitA, (i & 1) ? HIGH : LOW);
          digitalWrite (transmitB, (i & 2) ? HIGH : LOW);
          digitalWrite (transmitC, (i & 4) ? HIGH : LOW);
          delayMicroseconds(20);
          if(i==0){
            fader01 = analogRead(fader0);
          }
          if (i==1){
            fader02 = analogRead(fader0);
          }
        }
      }
    
      if (fader02 < fader01 - 10 && fader02 > faderMin) {
        pwm.setPWM(0,4096,0);
      }
      if (fader02 > fader01 - 10) {
        pwm.setPWM(0,0,0);
      }
      if (fader02 > fader01 + 10 && fader02 < faderMax) {
        pwm.setPWM(1,4096,0);
      }
      if (fader02 < fader01 + 10) {
        pwm.setPWM(1,0,0);
      }
    
      Serial.print(fader01);
      Serial.print(" : ");
      Serial.println(fader02);
    }
    to do's
    add midi in
    add touch
    add midi out only when being touched
    merge button, enc with fader code

  16. #41
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey all,

    im having problems with midi in as it needs to read system exclusive midi. i have been trying to get it to print out the data it gets with no luck.
    i am trying to get it to print out the 11bits it is being sent eg: F0 7F 7F 02 7F 06 19 01 1C 39 F7
    after that i want it to ignore any thing that isnt 11bits also only want it to read 3 bits in this 06 must always be 06 if it is then 19 (fader number) then 39 (where fader is at) are read next
    any help with this would be grate!!

  17. #42
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    dont no if any1 is reading this or not but can anyone read over this code. i had most of it working but then i hit the problem of not having enough power to power the chips. so waiting for a new power supply so i can get every thing powered up again. and in waiting i gone crazy and put everything to getter in code hoping i had done enough testing to have all the bits right.

    looking at the code there is a hell of a lot of if statments!!!
    hope they dont slow down the program to much.
    if anyone can help me with making the code smaller that would be fantastic!!!

    there will be 15 faders (was going to be 16 but worked out the program that i am planing on using it with didnt let me map it)
    there will also be around 250 buttons so i put in 256 into the code for now
    and 4 encoders

    Code:
    #include <MIDI.h>             //library's
    #include <Bounce.h>
    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>
    #include <Encoder.h>
    
    Adafruit_PWMServoDriver pwm0 = Adafruit_PWMServoDriver(0x40);  //I2C devices
    Adafruit_PWMServoDriver pwm1 = Adafruit_PWMServoDriver(0x41);
    
    const byte touch0 = 0;        //define pins
    const byte touch1 = 1;
    const byte transmitA = 2;
    const byte transmitB = 3;
    const byte transmitC = 4;
    const byte reciverA = 5;
    const byte reciverB = 6;
    const byte reciverC = 7;
    Encoder Enc0 (8,9);
    Encoder Enc1 (10,11);
    int led = 13;
    const byte button0 = 14;
    const byte button1 = 15;
    const byte button2 = 16;
    const byte button3 = 17;
    Encoder Enc2 (12,23);
    Encoder Enc3 (24,25);
    const byte fader0 = 22;
    const byte fader1 = A14;
    
    int i = 0;                  //verables
    char channelnum = 0;
    char channelloc = 0;
    int fader00 = 0;
    int fader01 = 0;
    int fader02 = 0;
    int fader03 = 0;
    int fader04 = 0;
    int fader05 = 0;
    int fader06 = 0;
    int fader07 = 0;
    int fader08 = 0;
    int fader09 = 0;
    int fader10 = 0;
    int fader11 = 0;
    int fader12 = 0;
    int fader13 = 0;
    int fader14 = 0;
    int newfader00 = 0;
    int newfader01 = 0;
    int newfader02 = 0;
    int newfader03 = 0;
    int newfader04 = 0;
    int newfader05 = 0;
    int newfader06 = 0;
    int newfader07 = 0;
    int newfader08 = 0;
    int newfader09 = 0;
    int newfader10 = 0;
    int newfader11 = 0;
    int newfader12 = 0;
    int newfader13 = 0;
    int newfader14 = 0;
    int touch00 = 0;
    int touch01 = 0;
    int touch02 = 0;
    int touch03 = 0;
    int touch04 = 0;
    int touch05 = 0;
    int touch06 = 0;
    int touch07 = 0;
    int touch08 = 0;
    int touch09 = 0;
    int touch10 = 0;
    int touch11 = 0;
    int touch12 = 0;
    int touch13 = 0;
    int touch14 = 0;
    double faderMax = 1019;
    double faderMin = 5;
    
    Bounce b0r0c0 = Bounce(button0,14);    //button bounce
    Bounce b0r0c1 = Bounce(button0,14);
    Bounce b0r0c2 = Bounce(button0,14);
    Bounce b0r0c3 = Bounce(button0,14);
    Bounce b0r0c4 = Bounce(button0,14);
    Bounce b0r0c5 = Bounce(button0,14);
    Bounce b0r0c6 = Bounce(button0,14);
    Bounce b0r0c7 = Bounce(button0,14);
    Bounce b0r1c0 = Bounce(button0,14);
    Bounce b0r1c1 = Bounce(button0,14);
    Bounce b0r1c2 = Bounce(button0,14);
    Bounce b0r1c3 = Bounce(button0,14);
    Bounce b0r1c4 = Bounce(button0,14);
    Bounce b0r1c5 = Bounce(button0,14);
    Bounce b0r1c6 = Bounce(button0,14);
    Bounce b0r1c7 = Bounce(button0,14);
    Bounce b0r2c0 = Bounce(button0,14);
    Bounce b0r2c1 = Bounce(button0,14);
    Bounce b0r2c2 = Bounce(button0,14);
    Bounce b0r2c3 = Bounce(button0,14);
    Bounce b0r2c4 = Bounce(button0,14);
    Bounce b0r2c5 = Bounce(button0,14);
    Bounce b0r2c6 = Bounce(button0,14);
    Bounce b0r2c7 = Bounce(button0,14);
    Bounce b0r3c0 = Bounce(button0,14);
    Bounce b0r3c1 = Bounce(button0,14);
    Bounce b0r3c2 = Bounce(button0,14);
    Bounce b0r3c3 = Bounce(button0,14);
    Bounce b0r3c4 = Bounce(button0,14);
    Bounce b0r3c5 = Bounce(button0,14);
    Bounce b0r3c6 = Bounce(button0,14);
    Bounce b0r3c7 = Bounce(button0,14);
    Bounce b0r4c0 = Bounce(button0,14);
    Bounce b0r4c1 = Bounce(button0,14);
    Bounce b0r4c2 = Bounce(button0,14);
    Bounce b0r4c3 = Bounce(button0,14);
    Bounce b0r4c4 = Bounce(button0,14);
    Bounce b0r4c5 = Bounce(button0,14);
    Bounce b0r4c6 = Bounce(button0,14);
    Bounce b0r4c7 = Bounce(button0,14);
    Bounce b0r5c0 = Bounce(button0,14);
    Bounce b0r5c1 = Bounce(button0,14);
    Bounce b0r5c2 = Bounce(button0,14);
    Bounce b0r5c3 = Bounce(button0,14);
    Bounce b0r5c4 = Bounce(button0,14);
    Bounce b0r5c5 = Bounce(button0,14);
    Bounce b0r5c6 = Bounce(button0,14);
    Bounce b0r5c7 = Bounce(button0,14);
    Bounce b0r6c0 = Bounce(button0,14);
    Bounce b0r6c1 = Bounce(button0,14);
    Bounce b0r6c2 = Bounce(button0,14);
    Bounce b0r6c3 = Bounce(button0,14);
    Bounce b0r6c4 = Bounce(button0,14);
    Bounce b0r6c5 = Bounce(button0,14);
    Bounce b0r6c6 = Bounce(button0,14);
    Bounce b0r6c7 = Bounce(button0,14);
    Bounce b0r7c0 = Bounce(button0,14);
    Bounce b0r7c1 = Bounce(button0,14);
    Bounce b0r7c2 = Bounce(button0,14);
    Bounce b0r7c3 = Bounce(button0,14);
    Bounce b0r7c4 = Bounce(button0,14);
    Bounce b0r7c5 = Bounce(button0,14);
    Bounce b0r7c6 = Bounce(button0,14);
    Bounce b0r7c7 = Bounce(button0,14);
    Bounce b1r0c0 = Bounce(button1,15);
    Bounce b1r0c1 = Bounce(button1,15);
    Bounce b1r0c2 = Bounce(button1,15);
    Bounce b1r0c3 = Bounce(button1,15);
    Bounce b1r0c4 = Bounce(button1,15);
    Bounce b1r0c5 = Bounce(button1,15);
    Bounce b1r0c6 = Bounce(button1,15);
    Bounce b1r0c7 = Bounce(button1,15);
    Bounce b1r1c0 = Bounce(button1,15);
    Bounce b1r1c1 = Bounce(button1,15);
    Bounce b1r1c2 = Bounce(button1,15);
    Bounce b1r1c3 = Bounce(button1,15);
    Bounce b1r1c4 = Bounce(button1,15);
    Bounce b1r1c5 = Bounce(button1,15);
    Bounce b1r1c6 = Bounce(button1,15);
    Bounce b1r1c7 = Bounce(button1,15);
    Bounce b1r2c0 = Bounce(button1,15);
    Bounce b1r2c1 = Bounce(button1,15);
    Bounce b1r2c2 = Bounce(button1,15);
    Bounce b1r2c3 = Bounce(button1,15);
    Bounce b1r2c4 = Bounce(button1,15);
    Bounce b1r2c5 = Bounce(button1,15);
    Bounce b1r2c6 = Bounce(button1,15);
    Bounce b1r2c7 = Bounce(button1,15);
    Bounce b1r3c0 = Bounce(button1,15);
    Bounce b1r3c1 = Bounce(button1,15);
    Bounce b1r3c2 = Bounce(button1,15);
    Bounce b1r3c3 = Bounce(button1,15);
    Bounce b1r3c4 = Bounce(button1,15);
    Bounce b1r3c5 = Bounce(button1,15);
    Bounce b1r3c6 = Bounce(button1,15);
    Bounce b1r3c7 = Bounce(button1,15);
    Bounce b1r4c0 = Bounce(button1,15);
    Bounce b1r4c1 = Bounce(button1,15);
    Bounce b1r4c2 = Bounce(button1,15);
    Bounce b1r4c3 = Bounce(button1,15);
    Bounce b1r4c4 = Bounce(button1,15);
    Bounce b1r4c5 = Bounce(button1,15);
    Bounce b1r4c6 = Bounce(button1,15);
    Bounce b1r4c7 = Bounce(button1,15);
    Bounce b1r5c0 = Bounce(button1,15);
    Bounce b1r5c1 = Bounce(button1,15);
    Bounce b1r5c2 = Bounce(button1,15);
    Bounce b1r5c3 = Bounce(button1,15);
    Bounce b1r5c4 = Bounce(button1,15);
    Bounce b1r5c5 = Bounce(button1,15);
    Bounce b1r5c6 = Bounce(button1,15);
    Bounce b1r5c7 = Bounce(button1,15);
    Bounce b1r6c0 = Bounce(button1,15);
    Bounce b1r6c1 = Bounce(button1,15);
    Bounce b1r6c2 = Bounce(button1,15);
    Bounce b1r6c3 = Bounce(button1,15);
    Bounce b1r6c4 = Bounce(button1,15);
    Bounce b1r6c5 = Bounce(button1,15);
    Bounce b1r6c6 = Bounce(button1,15);
    Bounce b1r6c7 = Bounce(button1,15);
    Bounce b1r7c0 = Bounce(button1,15);
    Bounce b1r7c1 = Bounce(button1,15);
    Bounce b1r7c2 = Bounce(button1,15);
    Bounce b1r7c3 = Bounce(button1,15);
    Bounce b1r7c4 = Bounce(button1,15);
    Bounce b1r7c5 = Bounce(button1,15);
    Bounce b1r7c6 = Bounce(button1,15);
    Bounce b1r7c7 = Bounce(button1,15);
    Bounce b2r0c0 = Bounce(button2,16);
    Bounce b2r0c1 = Bounce(button2,16);
    Bounce b2r0c2 = Bounce(button2,16);
    Bounce b2r0c3 = Bounce(button2,16);
    Bounce b2r0c4 = Bounce(button2,16);
    Bounce b2r0c5 = Bounce(button2,16);
    Bounce b2r0c6 = Bounce(button2,16);
    Bounce b2r0c7 = Bounce(button2,16);
    Bounce b2r1c0 = Bounce(button2,16);
    Bounce b2r1c1 = Bounce(button2,16);
    Bounce b2r1c2 = Bounce(button2,16);
    Bounce b2r1c3 = Bounce(button2,16);
    Bounce b2r1c4 = Bounce(button2,16);
    Bounce b2r1c5 = Bounce(button2,16);
    Bounce b2r1c6 = Bounce(button2,16);
    Bounce b2r1c7 = Bounce(button2,16);
    Bounce b2r2c0 = Bounce(button2,16);
    Bounce b2r2c1 = Bounce(button2,16);
    Bounce b2r2c2 = Bounce(button2,16);
    Bounce b2r2c3 = Bounce(button2,16);
    Bounce b2r2c4 = Bounce(button2,16);
    Bounce b2r2c5 = Bounce(button2,16);
    Bounce b2r2c6 = Bounce(button2,16);
    Bounce b2r2c7 = Bounce(button2,16);
    Bounce b2r3c0 = Bounce(button2,16);
    Bounce b2r3c1 = Bounce(button2,16);
    Bounce b2r3c2 = Bounce(button2,16);
    Bounce b2r3c3 = Bounce(button2,16);
    Bounce b2r3c4 = Bounce(button2,16);
    Bounce b2r3c5 = Bounce(button2,16);
    Bounce b2r3c6 = Bounce(button2,16);
    Bounce b2r3c7 = Bounce(button2,16);
    Bounce b2r4c0 = Bounce(button2,16);
    Bounce b2r4c1 = Bounce(button2,16);
    Bounce b2r4c2 = Bounce(button2,16);
    Bounce b2r4c3 = Bounce(button2,16);
    Bounce b2r4c4 = Bounce(button2,16);
    Bounce b2r4c5 = Bounce(button2,16);
    Bounce b2r4c6 = Bounce(button2,16);
    Bounce b2r4c7 = Bounce(button2,16);
    Bounce b2r5c0 = Bounce(button2,16);
    Bounce b2r5c1 = Bounce(button2,16);
    Bounce b2r5c2 = Bounce(button2,16);
    Bounce b2r5c3 = Bounce(button2,16);
    Bounce b2r5c4 = Bounce(button2,16);
    Bounce b2r5c5 = Bounce(button2,16);
    Bounce b2r5c6 = Bounce(button2,16);
    Bounce b2r5c7 = Bounce(button2,16);
    Bounce b2r6c0 = Bounce(button2,16);
    Bounce b2r6c1 = Bounce(button2,16);
    Bounce b2r6c2 = Bounce(button2,16);
    Bounce b2r6c3 = Bounce(button2,16);
    Bounce b2r6c4 = Bounce(button2,16);
    Bounce b2r6c5 = Bounce(button2,16);
    Bounce b2r6c6 = Bounce(button2,16);
    Bounce b2r6c7 = Bounce(button2,16);
    Bounce b2r7c0 = Bounce(button2,16);
    Bounce b2r7c1 = Bounce(button2,16);
    Bounce b2r7c2 = Bounce(button2,16);
    Bounce b2r7c3 = Bounce(button2,16);
    Bounce b2r7c4 = Bounce(button2,16);
    Bounce b2r7c5 = Bounce(button2,16);
    Bounce b2r7c6 = Bounce(button2,16);
    Bounce b2r7c7 = Bounce(button2,16);
    Bounce b3r0c0 = Bounce(button3,17);
    Bounce b3r0c1 = Bounce(button3,17);
    Bounce b3r0c2 = Bounce(button3,17);
    Bounce b3r0c3 = Bounce(button3,17);
    Bounce b3r0c4 = Bounce(button3,17);
    Bounce b3r0c5 = Bounce(button3,17);
    Bounce b3r0c6 = Bounce(button3,17);
    Bounce b3r0c7 = Bounce(button3,17);
    Bounce b3r1c0 = Bounce(button3,17);
    Bounce b3r1c1 = Bounce(button3,17);
    Bounce b3r1c2 = Bounce(button3,17);
    Bounce b3r1c3 = Bounce(button3,17);
    Bounce b3r1c4 = Bounce(button3,17);
    Bounce b3r1c5 = Bounce(button3,17);
    Bounce b3r1c6 = Bounce(button3,17);
    Bounce b3r1c7 = Bounce(button3,17);
    Bounce b3r2c0 = Bounce(button3,17);
    Bounce b3r2c1 = Bounce(button3,17);
    Bounce b3r2c2 = Bounce(button3,17);
    Bounce b3r2c3 = Bounce(button3,17);
    Bounce b3r2c4 = Bounce(button3,17);
    Bounce b3r2c5 = Bounce(button3,17);
    Bounce b3r2c6 = Bounce(button3,17);
    Bounce b3r2c7 = Bounce(button3,17);
    Bounce b3r3c0 = Bounce(button3,17);
    Bounce b3r3c1 = Bounce(button3,17);
    Bounce b3r3c2 = Bounce(button3,17);
    Bounce b3r3c3 = Bounce(button3,17);
    Bounce b3r3c4 = Bounce(button3,17);
    Bounce b3r3c5 = Bounce(button3,17);
    Bounce b3r3c6 = Bounce(button3,17);
    Bounce b3r3c7 = Bounce(button3,17);
    Bounce b3r4c0 = Bounce(button3,17);
    Bounce b3r4c1 = Bounce(button3,17);
    Bounce b3r4c2 = Bounce(button3,17);
    Bounce b3r4c3 = Bounce(button3,17);
    Bounce b3r4c4 = Bounce(button3,17);
    Bounce b3r4c5 = Bounce(button3,17);
    Bounce b3r4c6 = Bounce(button3,17);
    Bounce b3r4c7 = Bounce(button3,17);
    Bounce b3r5c0 = Bounce(button3,17);
    Bounce b3r5c1 = Bounce(button3,17);
    Bounce b3r5c2 = Bounce(button3,17);
    Bounce b3r5c3 = Bounce(button3,17);
    Bounce b3r5c4 = Bounce(button3,17);
    Bounce b3r5c5 = Bounce(button3,17);
    Bounce b3r5c6 = Bounce(button3,17);
    Bounce b3r5c7 = Bounce(button3,17);
    Bounce b3r6c0 = Bounce(button3,17);
    Bounce b3r6c1 = Bounce(button3,17);
    Bounce b3r6c2 = Bounce(button3,17);
    Bounce b3r6c3 = Bounce(button3,17);
    Bounce b3r6c4 = Bounce(button3,17);
    Bounce b3r6c5 = Bounce(button3,17);
    Bounce b3r6c6 = Bounce(button3,17);
    Bounce b3r6c7 = Bounce(button3,17);
    Bounce b3r7c0 = Bounce(button3,17);
    Bounce b3r7c1 = Bounce(button3,17);
    Bounce b3r7c2 = Bounce(button3,17);
    Bounce b3r7c3 = Bounce(button3,17);
    Bounce b3r7c4 = Bounce(button3,17);
    Bounce b3r7c5 = Bounce(button3,17);
    Bounce b3r7c6 = Bounce(button3,17);
    Bounce b3r7c7 = Bounce(button3,17);
    
    void setup() {
      Serial.begin(115200);
      pinMode(touch0,INPUT);      //pin mode
      pinMode(touch1,INPUT);
      pinMode(transmitA,OUTPUT);
      pinMode(transmitB,OUTPUT);
      pinMode(transmitC,OUTPUT);
      pinMode(reciverA,OUTPUT);
      pinMode(reciverB,OUTPUT);
      pinMode(reciverC,OUTPUT);
      pinMode(led,OUTPUT);
      digitalWrite (led, HIGH);
      pinMode(button0,INPUT);
      pinMode(button1,INPUT);
      pinMode(button2,INPUT);
      pinMode(button3,INPUT);
      pinMode(fader0,INPUT);
      pinMode(fader1,INPUT);
      pwm0.begin();           //I2C setting/start
      pwm1.begin();
      pwm0.setPWMFreq(1600);  // This is the maximum PWM frequency
      pwm1.setPWMFreq(1600);
      uint8_t twbrbackup = TWBR;
      TWBR = 12;              //freq = clock / (16 + (2 * TWBR))
    }
    //Encoder
    long old0Enc0 = -999;
    long old1Enc1 = -999;
    long old2Enc2 = -999;
    long old3Enc3 = -999;
    
    void loop(){
      usbMIDI.read();         //usb in
      if (usbMIDI.getType() == 7 && usbMIDI.getSysExArray()[1] == 127 && usbMIDI.getSysExArray()[5]==6)
      {
        channelnum = usbMIDI.getSysExArray()[6];
        channelloc = usbMIDI.getSysExArray()[9];
      }
      for(i=0;i<=63;i++) {    //button/fader scan/update
        {
          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){
            fader00 = analogRead(fader0);
            fader08 = analogRead(fader1);
            touch00 = touchRead(touch0);
            touch08 = touchRead(touch1);
            b0r0c0.update();
            b1r0c0.update();
            b2r0c0.update();
            b3r0c0.update();
          }
          if(i==1){
            b0r1c0.update();
            b1r1c0.update();
            b2r1c0.update();
            b3r1c0.update();
          }
          if(i==2){
            b0r2c0.update();
            b1r2c0.update();
            b2r2c0.update();
            b3r2c0.update();
          }
          if(i==3){
            b0r3c0.update();
            b1r3c0.update();
            b2r3c0.update();
            b3r3c0.update();
          }
          if(i==4){
            b0r4c0.update();
            b1r4c0.update();
            b2r4c0.update();
            b3r4c0.update();
          }
          if(i==5){
            b0r5c0.update();
            b1r5c0.update();
            b2r5c0.update();
            b3r5c0.update();
          }
          if(i==6){
            b0r6c0.update();
            b1r6c0.update();
            b2r6c0.update();
            b3r6c0.update();
          }
          if(i==7){
            b0r7c0.update();
            b1r7c0.update();
            b2r7c0.update();
            b3r7c0.update();
          }
          if(i==8){
            fader01 = analogRead(fader0);
            fader09 = analogRead(fader1);
            touch01 = touchRead(touch0);
            touch09 = touchRead(touch1);
            b0r0c1.update();
            b1r0c1.update();
            b2r0c1.update();
            b3r0c1.update();
          }
          if(i==9){
            b0r1c1.update();
            b1r1c1.update();
            b2r1c1.update();
            b3r1c1.update();
          }
          if(i==10){
            b0r2c1.update();
            b1r2c1.update();
            b2r2c1.update();
            b3r2c1.update();
          }
          if(i==11){
            b0r3c1.update();
            b1r3c1.update();
            b2r3c1.update();
            b3r3c1.update();
          }
          if(i==12){
            b0r4c1.update();
            b1r4c1.update();
            b2r4c1.update();
            b3r4c1.update();
          }
          if(i==13){
            b0r5c1.update();
            b1r5c1.update();
            b2r5c1.update();
            b3r5c1.update();
          }
          if(i==14){
            b0r6c1.update();
            b1r6c1.update();
            b2r6c1.update();
            b3r6c1.update();
          }
          if(i==15){
            b0r7c1.update();
            b1r7c1.update();
            b2r7c1.update();
            b3r7c1.update();
          }
          if(i==16){
            fader02 = analogRead(fader0);
            fader10 = analogRead(fader1);
            touch02 = touchRead(touch0);
            touch10 = touchRead(touch1);
            b0r0c2.update();
            b1r0c2.update();
            b2r0c2.update();
            b3r0c2.update();
          }
          if(i==17){
            b0r1c2.update();
            b1r1c2.update();
            b2r1c2.update();
            b3r1c2.update();
          }
          if(i==18){
            b0r2c2.update();
            b1r2c2.update();
            b2r2c2.update();
            b3r2c2.update();
          }
          if(i==19){
            b0r3c2.update();
            b1r3c2.update();
            b2r3c2.update();
            b3r3c2.update();
          }
          if(i==20){
            b0r4c2.update();
            b1r4c2.update();
            b2r4c2.update();
            b3r4c2.update();
          }
          if(i==21){
            b0r5c2.update();
            b1r5c2.update();
            b2r5c2.update();
            b3r5c2.update();
          }
          if(i==22){
            b0r6c2.update();
            b1r6c2.update();
            b2r6c2.update();
            b3r6c2.update();
          }
          if(i==23){
            b0r7c2.update();
            b1r7c2.update();
            b2r7c2.update();
            b3r7c2.update();
          }
          if(i==24){
            fader03 = analogRead(fader0);
            fader11 = analogRead(fader1);
            touch03 = touchRead(touch0);
            touch11 = touchRead(touch1);
            b0r0c3.update();
            b1r0c3.update();
            b2r0c3.update();
            b3r0c3.update();
          }
          if(i==25){
            b0r1c3.update();
            b1r1c3.update();
            b2r1c3.update();
            b3r1c3.update();
          }
          if(i==26){
            b0r2c3.update();
            b1r2c3.update();
            b2r2c3.update();
            b3r2c3.update();
          }
          if(i==27){
            b0r3c3.update();
            b1r3c3.update();
            b2r3c3.update();
            b3r3c3.update();
          }
          if(i==28){
            b0r4c3.update();
            b1r4c3.update();
            b2r4c3.update();
            b3r4c3.update();
          }
          if(i==29){
            b0r5c3.update();
            b1r5c3.update();
            b2r5c3.update();
            b3r5c3.update();
          }
          if(i==30){
            b0r6c3.update();
            b1r6c3.update();
            b2r6c3.update();
            b3r6c3.update();
          }
          if(i==31){
            b0r7c3.update();
            b1r7c3.update();
            b2r7c3.update();
            b3r7c3.update();
          }
          if(i==32){
            fader04 = analogRead(fader0);
            fader12 = analogRead(fader1);
            touch04 = touchRead(touch0);
            touch12 = touchRead(touch1);
            b0r0c4.update();
            b1r0c4.update();
            b2r0c4.update();
            b3r0c4.update();
          }
          if(i==33){
            b0r1c4.update();
            b1r1c4.update();
            b2r1c4.update();
            b3r1c4.update();
          }
          if(i==34){
            b0r2c4.update();
            b1r2c4.update();
            b2r2c4.update();
            b3r2c4.update();
          }
          if(i==35){
            b0r3c4.update();
            b1r3c4.update();
            b2r3c4.update();
            b3r3c4.update();
          }
          if(i==36){
            b0r4c4.update();
            b1r4c4.update();
            b2r4c4.update();
            b3r4c4.update();
          }
          if(i==37){
            b0r5c4.update();
            b1r5c4.update();
            b2r5c4.update();
            b3r5c4.update();
          }
          if(i==38){
            b0r6c4.update();
            b1r6c4.update();
            b2r6c4.update();
            b3r6c4.update();
          }
          if(i==39){
            b0r7c4.update();
            b1r7c4.update();
            b2r7c4.update();
            b3r7c4.update();
          }
          if(i==40){
            fader05 = analogRead(fader0);
            fader13 = analogRead(fader1);
            touch05 = touchRead(touch0);
            touch13 = touchRead(touch1);
            b0r0c5.update();
            b1r0c5.update();
            b2r0c5.update();
            b3r0c5.update();
          }
          if(i==41){
            b0r1c5.update();
            b1r1c5.update();
            b2r1c5.update();
            b3r1c5.update();
          }
          if(i==42){
            b0r2c5.update();
            b1r2c5.update();
            b2r2c5.update();
            b3r2c5.update();
          }
          if(i==43){
            b0r3c5.update();
            b1r3c5.update();
            b2r3c5.update();
            b3r3c5.update();
          }
          if(i==44){
            b0r4c5.update();
            b1r4c5.update();
            b2r4c5.update();
            b3r4c5.update();
          }
          if(i==45){
            b0r5c5.update();
            b1r5c5.update();
            b2r5c5.update();
            b3r5c5.update();
          }
          if(i==46){
            b0r6c5.update();
            b1r6c5.update();
            b2r6c5.update();
            b3r6c5.update();
          }
          if(i==47){
            b0r7c5.update();
            b1r7c5.update();
            b2r7c5.update();
            b3r7c5.update();
          }
          if(i==48){
            fader06 = analogRead(fader0);
            fader14 = analogRead(fader1);
            touch06 = touchRead(touch0);
            touch14 = touchRead(touch1);
            b0r0c6.update();
            b1r0c6.update();
            b2r0c6.update();
            b3r0c6.update();
          }
          if(i==49){
            b0r1c6.update();
            b1r1c6.update();
            b2r1c6.update();
            b3r1c6.update();
          }
          if(i==50){
            b0r2c6.update();
            b1r2c6.update();
            b2r2c6.update();
            b3r2c6.update();
          }
          if(i==51){
            b0r3c6.update();
            b1r3c6.update();
            b2r3c6.update();
            b3r3c6.update();
          }
          if(i==52){
            b0r4c6.update();
            b1r4c6.update();
            b2r4c6.update();
            b3r4c6.update();
          }
          if(i==53){
            b0r5c6.update();
            b1r5c6.update();
            b2r5c6.update();
            b3r5c6.update();
          }
          if(i==54){
            b0r6c6.update();
            b1r6c6.update();
            b2r6c6.update();
            b3r6c6.update();
          }
          if(i==55){
            b0r7c6.update();
            b1r7c6.update();
            b2r7c6.update();
            b3r7c6.update();
          }
          if(i==56){
            fader07 = analogRead(fader0);
            touch07 = touchRead(touch0);
            b0r0c7.update();
            b1r0c7.update();
            b2r0c7.update();
            b3r0c7.update();
          }
          if(i==57){
            b0r1c7.update();
            b1r1c7.update();
            b2r1c7.update();
            b3r1c7.update();
          }
          if(i==58){
            b0r2c7.update();
            b1r2c7.update();
            b2r2c7.update();
            b3r2c7.update();
          }
          if(i==59){
            b0r3c7.update();
            b1r3c7.update();
            b2r3c7.update();
            b3r3c7.update();
          }
          if(i==60){
            b0r4c7.update();
            b1r4c7.update();
            b2r4c7.update();
            b3r4c7.update();
          }
          if(i==61){
            b0r5c7.update();
            b1r5c7.update();
            b2r5c7.update();
            b3r5c7.update();
          }
          if(i==62){
            b0r6c7.update();
            b1r6c7.update();
            b2r6c7.update();
            b3r6c7.update();
          }
          if(i==63){
            b0r7c7.update();
            b1r7c7.update();
            b2r7c7.update();
            b3r7c7.update();
          }
    
        }
      }
      if(channelnum == 0,15,30,45){        //midi in to move faders
        newfader00 = channelloc;
      }
      if(channelnum == 1,16,31,46){
        newfader01 = channelloc;
      }
      if(channelnum == 2,17,32,47){
        newfader02 = channelloc;
      }
      if(channelnum == 3,18,33,48){
        newfader03 = channelloc;
      }
      if(channelnum == 4,19,34,49){
        newfader04 = channelloc;
      }
      if(channelnum == 5,20,35,50){
        newfader05 = channelloc;
      }
      if(channelnum == 6,21,36,51){
        newfader06 = channelloc;
      }
      if(channelnum == 7,22,37,52){
        newfader07 = channelloc;
      }
      if(channelnum == 8,23,38,53){
        newfader08 = channelloc;
      }
      if(channelnum == 9,24,39,54){
        newfader09 = channelloc;
      }
      if(channelnum == 10,25,40,55){
        newfader10 = channelloc;
      }
      if(channelnum == 11,26,41,56){
        newfader11 = channelloc;
      }
      if(channelnum == 12,27,42,57){
        newfader12 = channelloc;
      }
      if(channelnum == 13,28,43,58){
        newfader13 = channelloc;
      }
      if(channelnum == 14,29,44,59){
        newfader14 = channelloc;
      }
      if(touch00 < 2000){                        //moving of faders
        if(newfader00 < fader00 - 10 && newfader00 > faderMin) {
          pwm0.setPWM(0,4096,0);
        }
        if(newfader00 > fader00 - 10) {
          pwm0.setPWM(0,0,0);
        }
        if(newfader00 > fader00 + 10 && newfader00 < faderMax) {
          pwm0.setPWM(1,4096,0);
        }
        if(newfader00 < fader00 + 10) {
          pwm0.setPWM(1,0,0);
        }
      }
      if(touch01 < 2000){
        if(newfader01 < fader01 - 10 && newfader01 > faderMin) {
          pwm0.setPWM(2,4096,0);
        }
        if(newfader01 > fader00 - 10) {
          pwm0.setPWM(2,0,0);
        }
        if(newfader01 > fader01 + 10 && newfader01 < faderMax) {
          pwm0.setPWM(3,4096,0);
        }
        if(newfader01 < fader00 + 10) {
          pwm0.setPWM(3,0,0);
        }
      }
      if(touch02 < 2000){
        if(newfader02 < fader02 - 10 && newfader02 > faderMin) {
          pwm0.setPWM(4,4096,0);
        }
        if(newfader02 > fader02 - 10) {
          pwm0.setPWM(4,0,0);
        }
        if(newfader02 > fader02 + 10 && newfader02 < faderMax) {
          pwm0.setPWM(5,4096,0);
        }
        if(newfader02 < fader02 + 10) {
          pwm0.setPWM(5,0,0);
        }
      }
      if(touch03 < 2000){
        if(newfader03 < fader03 - 10 && newfader03 > faderMin) {
          pwm0.setPWM(6,4096,0);
        }
        if(newfader03 > fader03 - 10) {
          pwm0.setPWM(6,0,0);
        }
        if(newfader03 > fader03 + 10 && newfader03 < faderMax) {
          pwm0.setPWM(7,4096,0);
        }
        if(newfader03 < fader03 + 10) {
          pwm0.setPWM(7,0,0);
        }
      }
      if(touch04 < 2000){
        if(newfader04 < fader04 - 10 && newfader04 > faderMin) {
          pwm0.setPWM(8,4096,0);
        }
        if(newfader04 > fader04 - 10) {
          pwm0.setPWM(8,0,0);
        }
        if(newfader04 > fader04 + 10 && newfader04 < faderMax) {
          pwm0.setPWM(9,4096,0);
        }
        if(newfader04 < fader04 + 10) {
          pwm0.setPWM(9,0,0);
        }
      }
      if(touch05 < 2000){
        if(newfader05 < fader05 - 10 && newfader05 > faderMin) {
          pwm0.setPWM(10,4096,0);
        }
        if(newfader05 > fader05 - 10) {
          pwm0.setPWM(10,0,0);
        }
        if(newfader05 > fader05 + 10 && newfader05 < faderMax) {
          pwm0.setPWM(11,4096,0);
        }
        if(newfader05 < fader05 + 10) {
          pwm0.setPWM(11,0,0);
        }
      }
      if(touch06 < 2000){
        if(newfader06 < fader06 - 10 && newfader06 > faderMin) {
          pwm0.setPWM(12,4096,0);
        }
        if(newfader06 > fader06 - 10) {
          pwm0.setPWM(12,0,0);
        }
        if(newfader06 > fader06 + 10 && newfader06 < faderMax) {
          pwm0.setPWM(13,4096,0);
        }
        if(newfader06 < fader06 + 10) {
          pwm0.setPWM(13,0,0);
        }
      }
      if(touch07 < 2000){
        if(newfader07 < fader07 - 10 && newfader07 > faderMin) {
          pwm0.setPWM(14,4096,0);
        }
        if(newfader07 > fader07 - 10) {
          pwm0.setPWM(14,0,0);
        }
        if(newfader07 > fader07 + 10 && newfader07 < faderMax) {
          pwm0.setPWM(15,4096,0);
        }
        if(newfader07 < fader07 + 10) {
          pwm0.setPWM(15,0,0);
        }
      }
      if(touch08 < 2000){
        if(newfader08 < fader08 - 10 && newfader08 > faderMin) {
          pwm1.setPWM(0,4096,0);
        }
        if(newfader08 > fader08 - 10) {
          pwm1.setPWM(0,0,0);
        }
        if(newfader08 > fader08 + 10 && newfader08 < faderMax) {
          pwm1.setPWM(1,4096,0);
        }
        if(newfader08 < fader08 + 10) {
          pwm1.setPWM(1,0,0);
        }
      }
      if(touch09 <2000){
        if(newfader09 < fader09 - 10 && newfader09 > faderMin) {
          pwm1.setPWM(2,4096,0);
        }
        if(newfader09 > fader09 - 10) {
          pwm1.setPWM(2,0,0);
        }
        if(newfader09 > fader09 + 10 && newfader09 < faderMax) {
          pwm1.setPWM(3,4096,0);
        }
        if(newfader09 < fader09 + 10) {
          pwm1.setPWM(3,0,0);
        }
      }
      if(touch10 < 2000){
        if(newfader10 < fader10 - 10 && newfader10 > faderMin) {
          pwm1.setPWM(4,4096,0);
        }
        if(newfader10 > fader10 - 10) {
          pwm1.setPWM(4,0,0);
        }
        if(newfader10 > fader10 + 10 && newfader10 < faderMax) {
          pwm1.setPWM(5,4096,0);
        }
        if(newfader10 < fader10 + 10) {
          pwm1.setPWM(5,0,0);
        }
      }
      if(touch11 < 2000){
        if(newfader11 < fader11 - 10 && newfader11 > faderMin) {
          pwm1.setPWM(6,4096,0);
        }
        if(newfader11 > fader11 - 10) {
          pwm1.setPWM(6,0,0);
        }
        if(newfader11 > fader11 + 10 && newfader11 < faderMax) {
          pwm1.setPWM(7,4096,0);
        }
        if(newfader11 < fader11 + 10) {
          pwm1.setPWM(7,0,0);
        }
      }
      if(touch12 < 2000){
        if(newfader12 < fader12 - 10 && newfader12 > faderMin) {
          pwm1.setPWM(8,4096,0);
        }
        if(newfader12 > fader12 - 10) {
          pwm1.setPWM(8,0,0);
        }
        if(newfader12 > fader12 + 10 && newfader12 < faderMax) {
          pwm1.setPWM(9,4096,0);
        }
        if(newfader12 < fader12 + 10) {
          pwm1.setPWM(9,0,0);
        }
      }
      if(touch13 < 2000){
        if(newfader13 < fader13 - 10 && newfader13 > faderMin) {
          pwm1.setPWM(10,4096,0);
        }
        if(newfader13 > fader13 - 10) {
          pwm1.setPWM(10,0,0);
        }
        if(newfader13 > fader13 + 10 && newfader13 < faderMax) {
          pwm1.setPWM(11,4096,0);
        }
        if(newfader13 < fader13 + 10) {
          pwm1.setPWM(11,0,0);
        }
      }
      if(touch14 < 2000){
        if(newfader14 < fader14 - 10 && newfader14 > faderMin) {
          pwm1.setPWM(12,4096,0);
        }
        if(newfader14 > fader14 - 10) {
          pwm1.setPWM(12,0,0);
        }
        if(newfader14 > fader14 + 10 && newfader14 < faderMax) {
          pwm1.setPWM(13,4096,0);
        }
        if(newfader14 < fader14 + 10) {
          pwm1.setPWM(13,0,0);
        }
      }
      if(touch00>2000){         //midi out 
        usbMIDI.sendNoteOn(0,(fader00*0.125),3);
      }
      if(touch01>2000){
        usbMIDI.sendNoteOn(1,(fader01*0.125),3);
      }
      if(touch02>2000){
        usbMIDI.sendNoteOn(2,(fader02*0.125),3);
      }
      if(touch03>2000){
        usbMIDI.sendNoteOn(3,(fader03*0.125),3);
      }
      if(touch04>2000){
        usbMIDI.sendNoteOn(4,(fader04*0.125),3);
      }
      if(touch05>2000){
        usbMIDI.sendNoteOn(5,(fader05*0.125),3);
      }
      if(touch06>2000){
        usbMIDI.sendNoteOn(6,(fader06*0.125),3);
      }
      if(touch07>2000){
        usbMIDI.sendNoteOn(7,(fader07*0.125),3);
      }
      if(touch08>2000){
        usbMIDI.sendNoteOn(8,(fader08*0.125),3);
      }
      if(touch09>2000){
        usbMIDI.sendNoteOn(9,(fader09*0.125),3);
      }
      if(touch10>2000){
        usbMIDI.sendNoteOn(10,(fader10*0.125),3);
      }
      if(touch11>2000){
        usbMIDI.sendNoteOn(11,(fader11*0.125),3);
      }
      if(touch12>2000){
        usbMIDI.sendNoteOn(12,(fader12*0.125),3);
      }
      if(touch13>2000){
        usbMIDI.sendNoteOn(13,(fader13*0.125),3);
      }
      if(touch14>2000){
        usbMIDI.sendNoteOn(14,(fader14*0.125),3);
      }
      if(b0r0c0.risingEdge()){
        usbMIDI.sendNoteOn(0,127,1);
      }
      if(b0r0c1.risingEdge()){
        usbMIDI.sendNoteOn(1,127,1);
      }
      if(b0r0c2.risingEdge()){
        usbMIDI.sendNoteOn(2,127,1);
      }
      if(b0r0c3.risingEdge()){
        usbMIDI.sendNoteOn(3,127,1);
      }
      if(b0r0c4.risingEdge()){
        usbMIDI.sendNoteOn(4,127,1);
      }
      if(b0r0c5.risingEdge()){
        usbMIDI.sendNoteOn(5,127,1);
      }
      if(b0r0c6.risingEdge()){
        usbMIDI.sendNoteOn(6,127,1);
      }
      if(b0r0c7.risingEdge()){
        usbMIDI.sendNoteOn(7,127,1);
      }
      if(b0r1c0.risingEdge()){
        usbMIDI.sendNoteOn(8,127,1);
      }
      if(b0r1c1.risingEdge()){
        usbMIDI.sendNoteOn(9,127,1);
      }
      if(b0r1c2.risingEdge()){
        usbMIDI.sendNoteOn(10,127,1);
      }
      if(b0r1c3.risingEdge()){
        usbMIDI.sendNoteOn(11,127,1);
      }
      if(b0r1c4.risingEdge()){
        usbMIDI.sendNoteOn(12,127,1);
      }
      if(b0r1c5.risingEdge()){
        usbMIDI.sendNoteOn(13,127,1);
      }
      if(b0r1c6.risingEdge()){
        usbMIDI.sendNoteOn(14,127,1);
      }
      if(b0r1c7.risingEdge()){
        usbMIDI.sendNoteOn(15,127,1);
      }
      if(b0r2c0.risingEdge()){
        usbMIDI.sendNoteOn(16,127,1);
      }
      if(b0r2c1.risingEdge()){
        usbMIDI.sendNoteOn(17,127,1);
      }
      if(b0r2c2.risingEdge()){
        usbMIDI.sendNoteOn(18,127,1);
      }
      if(b0r2c3.risingEdge()){
        usbMIDI.sendNoteOn(19,127,1);
      }
      if(b0r2c4.risingEdge()){
        usbMIDI.sendNoteOn(20,127,1);
      }
      if(b0r2c5.risingEdge()){
        usbMIDI.sendNoteOn(21,127,1);
      }
      if(b0r2c6.risingEdge()){
        usbMIDI.sendNoteOn(22,127,1);
      }
      if(b0r2c7.risingEdge()){
        usbMIDI.sendNoteOn(23,127,1);
      }
      if(b0r3c0.risingEdge()){
        usbMIDI.sendNoteOn(24,127,1);
      }
      if(b0r3c1.risingEdge()){
        usbMIDI.sendNoteOn(25,127,1);
      }
      if(b0r3c2.risingEdge()){
        usbMIDI.sendNoteOn(26,127,1);
      }
      if(b0r3c3.risingEdge()){
        usbMIDI.sendNoteOn(27,127,1);
      }
      if(b0r3c4.risingEdge()){
        usbMIDI.sendNoteOn(28,127,1);
      }
      if(b0r3c5.risingEdge()){
        usbMIDI.sendNoteOn(29,127,1);
      }
      if(b0r3c6.risingEdge()){
        usbMIDI.sendNoteOn(30,127,1);
      }
      if(b0r3c7.risingEdge()){
        usbMIDI.sendNoteOn(31,127,1);
      }
      if(b0r4c0.risingEdge()){
        usbMIDI.sendNoteOn(32,127,1);
      }
      if(b0r4c1.risingEdge()){
        usbMIDI.sendNoteOn(33,127,1);
      }
      if(b0r4c2.risingEdge()){
        usbMIDI.sendNoteOn(34,127,1);
      }
      if(b0r4c3.risingEdge()){
        usbMIDI.sendNoteOn(35,127,1);
      }
      if(b0r4c4.risingEdge()){
        usbMIDI.sendNoteOn(36,127,1);
      }
      if(b0r4c5.risingEdge()){
        usbMIDI.sendNoteOn(37,127,1);
      }
      if(b0r4c6.risingEdge()){
        usbMIDI.sendNoteOn(38,127,1);
      }
      if(b0r4c7.risingEdge()){
        usbMIDI.sendNoteOn(39,127,1);
      }
      if(b0r5c0.risingEdge()){
        usbMIDI.sendNoteOn(40,127,1);
      }
      if(b0r5c1.risingEdge()){
        usbMIDI.sendNoteOn(41,127,1);
      }
      if(b0r5c2.risingEdge()){
        usbMIDI.sendNoteOn(42,127,1);
      }
      if(b0r5c3.risingEdge()){
        usbMIDI.sendNoteOn(43,127,1);
      }
      if(b0r5c4.risingEdge()){
        usbMIDI.sendNoteOn(44,127,1);
      }
      if(b0r5c5.risingEdge()){
        usbMIDI.sendNoteOn(45,127,1);
      }
      if(b0r5c6.risingEdge()){
        usbMIDI.sendNoteOn(46,127,1);
      }
      if(b0r5c7.risingEdge()){
        usbMIDI.sendNoteOn(47,127,1);
      }
      if(b0r6c0.risingEdge()){
        usbMIDI.sendNoteOn(48,127,1);
      }
      if(b0r6c1.risingEdge()){
        usbMIDI.sendNoteOn(49,127,1);
      }
      if(b0r6c2.risingEdge()){
        usbMIDI.sendNoteOn(50,127,1);
      }
      if(b0r6c3.risingEdge()){
        usbMIDI.sendNoteOn(51,127,1);
      }
      if(b0r6c4.risingEdge()){
        usbMIDI.sendNoteOn(52,127,1);
      }
      if(b0r6c5.risingEdge()){
        usbMIDI.sendNoteOn(53,127,1);
      }
      if(b0r6c6.risingEdge()){
        usbMIDI.sendNoteOn(54,127,1);
      }
      if(b0r6c7.risingEdge()){
        usbMIDI.sendNoteOn(55,127,1);
      }
      if(b0r7c0.risingEdge()){
        usbMIDI.sendNoteOn(56,127,1);
      }
      if(b0r7c1.risingEdge()){
        usbMIDI.sendNoteOn(57,127,1);
      }
      if(b0r7c2.risingEdge()){
        usbMIDI.sendNoteOn(58,127,1);
      }
      if(b0r7c3.risingEdge()){
        usbMIDI.sendNoteOn(59,127,1);
      }
      if(b0r7c4.risingEdge()){
        usbMIDI.sendNoteOn(60,127,1);
      }
      if(b0r7c5.risingEdge()){
        usbMIDI.sendNoteOn(61,127,1);
      }
      if(b0r7c6.risingEdge()){
        usbMIDI.sendNoteOn(62,127,1);
      }
      if(b0r7c7.risingEdge()){
        usbMIDI.sendNoteOn(63,127,1);
      }
      if(b1r0c0.risingEdge()){
        usbMIDI.sendNoteOn(64,127,1);
      }
      if(b1r0c1.risingEdge()){
        usbMIDI.sendNoteOn(65,127,1);
      }
      if(b1r0c2.risingEdge()){
        usbMIDI.sendNoteOn(66,127,1);
      }
      if(b1r0c3.risingEdge()){
        usbMIDI.sendNoteOn(67,127,1);
      }
      if(b1r0c4.risingEdge()){
        usbMIDI.sendNoteOn(68,127,1);
      }
      if(b1r0c5.risingEdge()){
        usbMIDI.sendNoteOn(69,127,1);
      }
      if(b1r0c6.risingEdge()){
        usbMIDI.sendNoteOn(70,127,1);
      }
      if(b1r0c7.risingEdge()){
        usbMIDI.sendNoteOn(71,127,1);
      }
      if(b1r1c0.risingEdge()){
        usbMIDI.sendNoteOn(72,127,1);
      }
      if(b1r1c1.risingEdge()){
        usbMIDI.sendNoteOn(73,127,1);
      }
      if(b1r1c2.risingEdge()){
        usbMIDI.sendNoteOn(74,127,1);
      }
      if(b1r1c3.risingEdge()){
        usbMIDI.sendNoteOn(75,127,1);
      }
      if(b1r1c4.risingEdge()){
        usbMIDI.sendNoteOn(76,127,1);
      }
      if(b1r1c5.risingEdge()){
        usbMIDI.sendNoteOn(77,127,1);
      }
      if(b1r1c6.risingEdge()){
        usbMIDI.sendNoteOn(78,127,1);
      }
      if(b1r1c7.risingEdge()){
        usbMIDI.sendNoteOn(79,127,1);
      }
      if(b1r2c0.risingEdge()){
        usbMIDI.sendNoteOn(80,127,1);
      }
      if(b1r2c1.risingEdge()){
        usbMIDI.sendNoteOn(81,127,1);
      }
      if(b1r2c2.risingEdge()){
        usbMIDI.sendNoteOn(82,127,1);
      }
      if(b1r2c3.risingEdge()){
        usbMIDI.sendNoteOn(83,127,1);
      }
      if(b1r2c4.risingEdge()){
        usbMIDI.sendNoteOn(84,127,1);
      }
      if(b1r2c5.risingEdge()){
        usbMIDI.sendNoteOn(85,127,1);
      }
      if(b1r2c6.risingEdge()){
        usbMIDI.sendNoteOn(86,127,1);
      }
      if(b1r2c7.risingEdge()){
        usbMIDI.sendNoteOn(87,127,1);
      }
      if(b1r3c0.risingEdge()){
        usbMIDI.sendNoteOn(88,127,1);
      }
      if(b1r3c1.risingEdge()){
        usbMIDI.sendNoteOn(89,127,1);
      }
      if(b1r3c2.risingEdge()){
        usbMIDI.sendNoteOn(90,127,1);
      }
      if(b1r3c3.risingEdge()){
        usbMIDI.sendNoteOn(91,127,1);
      }
      if(b1r3c4.risingEdge()){
        usbMIDI.sendNoteOn(92,127,1);
      }
      if(b1r3c5.risingEdge()){
        usbMIDI.sendNoteOn(93,127,1);
      }
      if(b1r3c6.risingEdge()){
        usbMIDI.sendNoteOn(94,127,1);
      }
      if(b1r3c7.risingEdge()){
        usbMIDI.sendNoteOn(95,127,1);
      }
      if(b1r4c0.risingEdge()){
        usbMIDI.sendNoteOn(96,127,1);
      }
      if(b1r4c1.risingEdge()){
        usbMIDI.sendNoteOn(97,127,1);
      }
      if(b1r4c2.risingEdge()){
        usbMIDI.sendNoteOn(98,127,1);
      }
      if(b1r4c3.risingEdge()){
        usbMIDI.sendNoteOn(99,127,1);
      }
      if(b1r4c4.risingEdge()){
        usbMIDI.sendNoteOn(100,127,1);
      }
      if(b1r4c5.risingEdge()){
        usbMIDI.sendNoteOn(101,127,1);
      }
      if(b1r4c6.risingEdge()){
        usbMIDI.sendNoteOn(102,127,1);
      }
      if(b1r4c7.risingEdge()){
        usbMIDI.sendNoteOn(103,127,1);
      }
      if(b1r5c0.risingEdge()){
        usbMIDI.sendNoteOn(104,127,1);
      }
      if(b1r5c1.risingEdge()){
        usbMIDI.sendNoteOn(105,127,1);
      }
      if(b1r5c2.risingEdge()){
        usbMIDI.sendNoteOn(106,127,1);
      }
      if(b1r5c3.risingEdge()){
        usbMIDI.sendNoteOn(107,127,1);
      }
      if(b1r5c4.risingEdge()){
        usbMIDI.sendNoteOn(108,127,1);
      }
      if(b1r5c5.risingEdge()){
        usbMIDI.sendNoteOn(109,127,1);
      }
      if(b1r5c6.risingEdge()){
        usbMIDI.sendNoteOn(110,127,1);
      }
      if(b1r5c7.risingEdge()){
        usbMIDI.sendNoteOn(111,127,2);
      }
      if(b1r6c0.risingEdge()){
        usbMIDI.sendNoteOn(112,127,1);
      }
      if(b1r6c1.risingEdge()){
        usbMIDI.sendNoteOn(112,127,1);
      }
      if(b1r6c2.risingEdge()){
        usbMIDI.sendNoteOn(113,127,1);
      }
      if(b1r6c3.risingEdge()){
        usbMIDI.sendNoteOn(114,127,1);
      }
      if(b1r6c4.risingEdge()){
        usbMIDI.sendNoteOn(115,127,1);
      }
      if(b1r6c5.risingEdge()){
        usbMIDI.sendNoteOn(116,127,1);
      }
      if(b1r6c6.risingEdge()){
        usbMIDI.sendNoteOn(117,127,1);
      }
      if(b1r6c7.risingEdge()){
        usbMIDI.sendNoteOn(118,127,1);
      }
      if(b1r7c0.risingEdge()){
        usbMIDI.sendNoteOn(119,127,1);
      }
      if(b1r7c1.risingEdge()){
        usbMIDI.sendNoteOn(120,127,1);
      }
      if(b1r7c2.risingEdge()){
        usbMIDI.sendNoteOn(121,127,1);
      }
      if(b1r7c3.risingEdge()){
        usbMIDI.sendNoteOn(122,127,1);
      }
      if(b1r7c4.risingEdge()){
        usbMIDI.sendNoteOn(123,127,1);
      }
      if(b1r7c5.risingEdge()){
        usbMIDI.sendNoteOn(124,127,1);
      }
      if(b1r7c6.risingEdge()){
        usbMIDI.sendNoteOn(125,127,1);
      }
      if(b1r7c7.risingEdge()){
        usbMIDI.sendNoteOn(126,127,1);
      }
      if(b2r0c0.risingEdge()){
        usbMIDI.sendNoteOn(0,127,1);
      }
      if(b2r0c1.risingEdge()){
        usbMIDI.sendNoteOn(1,127,2);
      }
      if(b2r0c2.risingEdge()){
        usbMIDI.sendNoteOn(2,127,2);
      }
      if(b2r0c3.risingEdge()){
        usbMIDI.sendNoteOn(3,127,2);
      }
      if(b2r0c4.risingEdge()){
        usbMIDI.sendNoteOn(4,127,2);
      }
      if(b2r0c5.risingEdge()){
        usbMIDI.sendNoteOn(5,127,2);
      }
      if(b2r0c6.risingEdge()){
        usbMIDI.sendNoteOn(6,127,2);
      }
      if(b2r0c7.risingEdge()){
        usbMIDI.sendNoteOn(7,127,2);
      }
      if(b2r1c0.risingEdge()){
        usbMIDI.sendNoteOn(8,127,2);
      }
      if(b2r1c1.risingEdge()){
        usbMIDI.sendNoteOn(9,127,2);
      }
      if(b2r1c2.risingEdge()){
        usbMIDI.sendNoteOn(10,127,2);
      }
      if(b2r1c3.risingEdge()){
        usbMIDI.sendNoteOn(11,127,2);
      }
      if(b2r1c4.risingEdge()){
        usbMIDI.sendNoteOn(12,127,2);
      }
      if(b2r1c5.risingEdge()){
        usbMIDI.sendNoteOn(13,127,2);
      }
      if(b2r1c6.risingEdge()){
        usbMIDI.sendNoteOn(14,127,2);
      }
      if(b2r1c7.risingEdge()){
        usbMIDI.sendNoteOn(15,127,2);
      }
      if(b2r2c0.risingEdge()){
        usbMIDI.sendNoteOn(16,127,2);
      }
      if(b2r2c1.risingEdge()){
        usbMIDI.sendNoteOn(17,127,2);
      }
      if(b2r2c2.risingEdge()){
        usbMIDI.sendNoteOn(18,127,2);
      }
      if(b2r2c3.risingEdge()){
        usbMIDI.sendNoteOn(19,127,2);
      }
      if(b2r2c4.risingEdge()){
        usbMIDI.sendNoteOn(20,127,2);
      }
      if(b2r2c5.risingEdge()){
        usbMIDI.sendNoteOn(21,127,2);
      }
      if(b2r2c6.risingEdge()){
        usbMIDI.sendNoteOn(22,127,2);
      }
      if(b2r2c7.risingEdge()){
        usbMIDI.sendNoteOn(23,127,2);
      }
      if(b2r3c0.risingEdge()){
        usbMIDI.sendNoteOn(24,127,2);
      }
      if(b2r3c1.risingEdge()){
        usbMIDI.sendNoteOn(25,127,2);
      }
      if(b2r3c2.risingEdge()){
        usbMIDI.sendNoteOn(26,127,2);
      }
      if(b2r3c3.risingEdge()){
        usbMIDI.sendNoteOn(27,127,2);
      }
      if(b2r3c4.risingEdge()){
        usbMIDI.sendNoteOn(28,127,2);
      }
      if(b2r3c5.risingEdge()){
        usbMIDI.sendNoteOn(29,127,2);
      }
      if(b2r3c6.risingEdge()){
        usbMIDI.sendNoteOn(30,127,2);
      }
      if(b2r3c7.risingEdge()){
        usbMIDI.sendNoteOn(31,127,2);
      }
      if(b2r4c0.risingEdge()){
        usbMIDI.sendNoteOn(32,127,2);
      }
      if(b2r4c1.risingEdge()){
        usbMIDI.sendNoteOn(33,127,2);
      }
      if(b2r4c2.risingEdge()){
        usbMIDI.sendNoteOn(34,127,2);
      }
      if(b2r4c3.risingEdge()){
        usbMIDI.sendNoteOn(35,127,2);
      }
      if(b2r4c4.risingEdge()){
        usbMIDI.sendNoteOn(36,127,2);
      }
      if(b2r4c5.risingEdge()){
        usbMIDI.sendNoteOn(37,127,2);
      }
      if(b2r4c6.risingEdge()){
        usbMIDI.sendNoteOn(38,127,2);
      }
      if(b2r4c7.risingEdge()){
        usbMIDI.sendNoteOn(39,127,2);
      }
      if(b2r5c0.risingEdge()){
        usbMIDI.sendNoteOn(40,127,2);
      }
      if(b2r5c1.risingEdge()){
        usbMIDI.sendNoteOn(41,127,2);
      }
      if(b2r5c2.risingEdge()){
        usbMIDI.sendNoteOn(42,127,2);
      }
      if(b2r5c3.risingEdge()){
        usbMIDI.sendNoteOn(43,127,2);
      }
      if(b2r5c4.risingEdge()){
        usbMIDI.sendNoteOn(44,127,2);
      }
      if(b2r5c5.risingEdge()){
        usbMIDI.sendNoteOn(45,127,2);
      }
      if(b2r5c6.risingEdge()){
        usbMIDI.sendNoteOn(46,127,2);
      }
      if(b2r5c7.risingEdge()){
        usbMIDI.sendNoteOn(47,127,2);
      }
      if(b2r6c0.risingEdge()){
        usbMIDI.sendNoteOn(48,127,2);
      }
      if(b2r6c1.risingEdge()){
        usbMIDI.sendNoteOn(49,127,2);
      }
      if(b2r6c2.risingEdge()){
        usbMIDI.sendNoteOn(50,127,2);
      }
      if(b2r6c3.risingEdge()){
        usbMIDI.sendNoteOn(51,127,2);
      }
      if(b2r6c4.risingEdge()){
        usbMIDI.sendNoteOn(52,127,2);
      }
      if(b2r6c5.risingEdge()){
        usbMIDI.sendNoteOn(53,127,2);
      }
      if(b2r6c6.risingEdge()){
        usbMIDI.sendNoteOn(54,127,2);
      }
      if(b2r6c7.risingEdge()){
        usbMIDI.sendNoteOn(55,127,2);
      }
      if(b2r7c0.risingEdge()){
        usbMIDI.sendNoteOn(56,127,2);
      }
      if(b2r7c1.risingEdge()){
        usbMIDI.sendNoteOn(57,127,2);
      }
      if(b2r7c2.risingEdge()){
        usbMIDI.sendNoteOn(58,127,2);
      }
      if(b2r7c3.risingEdge()){
        usbMIDI.sendNoteOn(59,127,2);
      }
      if(b2r7c4.risingEdge()){
        usbMIDI.sendNoteOn(60,127,2);
      }
      if(b2r7c5.risingEdge()){
        usbMIDI.sendNoteOn(61,127,2);
      }
      if(b2r7c6.risingEdge()){
        usbMIDI.sendNoteOn(62,127,2);
      }
      if(b2r7c7.risingEdge()){
        usbMIDI.sendNoteOn(63,127,2);
      }
      if(b3r0c0.risingEdge()){
        usbMIDI.sendNoteOn(64,127,2);
      }
      if(b3r0c1.risingEdge()){
        usbMIDI.sendNoteOn(65,127,2);
      }
      if(b3r0c2.risingEdge()){
        usbMIDI.sendNoteOn(66,127,2);
      }
      if(b3r0c3.risingEdge()){
        usbMIDI.sendNoteOn(67,127,2);
      }
      if(b3r0c4.risingEdge()){
        usbMIDI.sendNoteOn(68,127,2);
      }
      if(b3r0c5.risingEdge()){
        usbMIDI.sendNoteOn(69,127,2);
      }
      if(b3r0c6.risingEdge()){
        usbMIDI.sendNoteOn(70,127,2);
      }
      if(b3r0c7.risingEdge()){
        usbMIDI.sendNoteOn(71,127,2);
      }
      if(b3r1c0.risingEdge()){
        usbMIDI.sendNoteOn(72,127,2);
      }
      if(b3r1c1.risingEdge()){
        usbMIDI.sendNoteOn(73,127,2);
      }
      if(b3r1c2.risingEdge()){
        usbMIDI.sendNoteOn(74,127,2);
      }
      if(b3r1c3.risingEdge()){
        usbMIDI.sendNoteOn(75,127,2);
      }
      if(b3r1c4.risingEdge()){
        usbMIDI.sendNoteOn(76,127,2);
      }
      if(b3r1c5.risingEdge()){
        usbMIDI.sendNoteOn(77,127,2);
      }
      if(b3r1c6.risingEdge()){
        usbMIDI.sendNoteOn(78,127,2);
      }
      if(b3r1c7.risingEdge()){
        usbMIDI.sendNoteOn(79,127,2);
      }
      if(b3r2c0.risingEdge()){
        usbMIDI.sendNoteOn(80,127,2);
      }
      if(b3r2c1.risingEdge()){
        usbMIDI.sendNoteOn(81,127,2);
      }
      if(b3r2c2.risingEdge()){
        usbMIDI.sendNoteOn(82,127,2);
      }
      if(b3r2c3.risingEdge()){
        usbMIDI.sendNoteOn(83,127,2);
      }
      if(b3r2c4.risingEdge()){
        usbMIDI.sendNoteOn(84,127,2);
      }
      if(b3r2c5.risingEdge()){
        usbMIDI.sendNoteOn(85,127,2);
      }
      if(b3r2c6.risingEdge()){
        usbMIDI.sendNoteOn(86,127,2);
      }
      if(b3r2c7.risingEdge()){
        usbMIDI.sendNoteOn(87,127,2);
      }
      if(b3r3c0.risingEdge()){
        usbMIDI.sendNoteOn(88,127,2);
      }
      if(b3r3c1.risingEdge()){
        usbMIDI.sendNoteOn(89,127,2);
      }
      if(b3r3c2.risingEdge()){
        usbMIDI.sendNoteOn(90,127,2);
      }
      if(b3r3c3.risingEdge()){
        usbMIDI.sendNoteOn(91,127,2);
      }
      if(b3r3c4.risingEdge()){
        usbMIDI.sendNoteOn(92,127,2);
      }
      if(b3r3c5.risingEdge()){
        usbMIDI.sendNoteOn(93,127,2);
      }
      if(b3r3c6.risingEdge()){
        usbMIDI.sendNoteOn(94,127,2);
      }
      if(b3r3c7.risingEdge()){
        usbMIDI.sendNoteOn(95,127,2);
      }
      if(b3r4c0.risingEdge()){
        usbMIDI.sendNoteOn(96,127,2);
      }
      if(b3r4c1.risingEdge()){
        usbMIDI.sendNoteOn(97,127,2);
      }
      if(b3r4c2.risingEdge()){
        usbMIDI.sendNoteOn(98,127,2);
      }
      if(b3r4c3.risingEdge()){
        usbMIDI.sendNoteOn(99,127,2);
      }
      if(b3r4c4.risingEdge()){
        usbMIDI.sendNoteOn(100,127,2);
      }
      if(b3r4c5.risingEdge()){
        usbMIDI.sendNoteOn(101,127,2);
      }
      if(b3r4c6.risingEdge()){
        usbMIDI.sendNoteOn(102,127,2);
      }
      if(b3r4c7.risingEdge()){
        usbMIDI.sendNoteOn(103,127,2);
      }
      if(b3r5c0.risingEdge()){
        usbMIDI.sendNoteOn(104,127,2);
      }
      if(b3r5c1.risingEdge()){
        usbMIDI.sendNoteOn(105,127,2);
      }
      if(b3r5c2.risingEdge()){
        usbMIDI.sendNoteOn(106,127,2);
      }
      if(b3r5c3.risingEdge()){
        usbMIDI.sendNoteOn(107,127,2);
      }
      if(b3r5c4.risingEdge()){
        usbMIDI.sendNoteOn(108,127,2);
      }
      if(b3r5c5.risingEdge()){
        usbMIDI.sendNoteOn(109,127,2);
      }
      if(b3r5c6.risingEdge()){
        usbMIDI.sendNoteOn(110,127,2);
      }
      if(b3r5c7.risingEdge()){
        usbMIDI.sendNoteOn(111,127,2);
      }
      if(b3r6c0.risingEdge()){
        usbMIDI.sendNoteOn(112,127,2);
      }
      if(b3r6c1.risingEdge()){
        usbMIDI.sendNoteOn(113,127,2);
      }
      if(b3r6c2.risingEdge()){
        usbMIDI.sendNoteOn(114,127,2);
      }
      if(b3r6c3.risingEdge()){
        usbMIDI.sendNoteOn(115,127,2);
      }
      if(b3r6c4.risingEdge()){
        usbMIDI.sendNoteOn(116,127,2);
      }
      if(b3r6c5.risingEdge()){
        usbMIDI.sendNoteOn(117,127,2);
      }
      if(b3r6c6.risingEdge()){
        usbMIDI.sendNoteOn(118,127,2);
      }
      if(b3r6c7.risingEdge()){
        usbMIDI.sendNoteOn(119,127,2);
      }
      if(b3r7c0.risingEdge()){
        usbMIDI.sendNoteOn(120,127,2);
      }
      if(b3r7c1.risingEdge()){
        usbMIDI.sendNoteOn(121,127,2);
      }
      if(b3r7c2.risingEdge()){
        usbMIDI.sendNoteOn(122,127,2);
      }
      if(b3r7c3.risingEdge()){
        usbMIDI.sendNoteOn(123,127,2);
      }
      if(b3r7c4.risingEdge()){
        usbMIDI.sendNoteOn(124,127,2);
      }
      if(b3r7c5.risingEdge()){
        usbMIDI.sendNoteOn(125,127,2);
      }
      if(b3r7c6.risingEdge()){
        usbMIDI.sendNoteOn(126,127,2);
      }
      if(b3r7c7.risingEdge()){
        usbMIDI.sendNoteOn(127,127,2);
      } 
    }

  18. #43
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    25,082
    There are ways to create arrays of pointers or references to the objects, and then use loops for compact code. But that gets into some more advanced programming syntax, which really doesn't buy you much real benefit. Simply duplicating the code works just as well.

  19. #44
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    thanks Paul. thats good to no

    i have been sraching my head trying to work this out.
    what im trying to do at the moment is to do with the motors on the faders
    at the moment faders move at full speed to the target. what i want to do is when its closer that it goes to half speed. but i cant think of how to it.

    Code:
      if(touch00 < 2000){                        //moving of faders
        if(newfader00 < fader00 - 150 && newfader00 > faderMin) {
          pwm0.setPWM(0,4096,0);
        }
        if(????????) {                            //if fader00 is between 10 - 150 from newfader00 go to half speed
          pwm0.setPWM(0,2048,0);
        }
        if(newfader00 > fader00 - 10) {
          pwm0.setPWM(0,0,0);
        }
        if(newfader00 > fader00 + 150 && newfader00 < faderMax) {
          pwm0.setPWM(1,4096,0);
        }
        if(????????) {                           //if fader00 is between 10 - 150 from newfader00 go to half speed
          pwm0.setPWM(1,2048,0);
        }
        if(newfader00 < fader00 + 10) {
          pwm0.setPWM(1,0,0);
        }
      }

  20. #45
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    never mind with the last comment. for some reason the faders wont move without the pwm being at 4096.any less it just wont work. no idea why
    i tried
    (0,2048,0)
    (0,2048,2048)
    (0,4095,0)
    (0,4095,1)
    (0,0,4095)
    (0,1,4095)
    non of them worked
    or it could be couse im useing 5v for the faders instead of 10v
    Last edited by Nick1802; 11-28-2014 at 06:36 AM.

  21. #46
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    So if any1 see this post and thinks here's another post with out a complete code done. I have put it on the back burner until I have time to work on this project again.

  22. #47
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey all, back working on this project again now. yay finely!!!
    been so long sence doing any coding i had to strip the code all the way back to just buttons and add bit by bit again just to remember what bit of code did what.
    so now that i have cort back up i noticed the midi wasnt right as the program and the teensy misbehaved when working the faders. worked out that the teensy is looking for SysEx midi code that it was getting but i had the teensy sending midi notes for the faders when it needed to be sending SysEx midi instead. so this is where i think i have become a lil stuck. the compiler keeps giving me errors but still compiles. :S
    im using arduino 1.6.1 (b4 i was using 1.0.6)

    Using library Adafruit_PWMServoDriver in folder: C:\Users\nick\Documents\Arduino\libraries\Adafruit _PWMServoDriver (1.0.x format)
    In file included from C:\Users\nick\Dropbox\nicks crap\teensy stuff\Arduino\hardware\teensy\avr\cores\teensy3/Stream.h:24:0,
    from C:\Users\nick\Dropbox\nicks crap\teensy stuff\Arduino\hardware\teensy\avr\cores\teensy3/HardwareSerial.h:163,
    from C:\Users\nick\Dropbox\nicks crap\teensy stuff\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:16,
    from C:\Users\nick\Dropbox\nicks crap\teensy stuff\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:1,
    from C:\Users\nick\Documents\Arduino\libraries\Encoder/Encoder.h:33,
    from matix_enc_fader_midi_motori2c.ino:2:
    matix_enc_fader_midi_motori2c.ino: In function 'void loop()':
    C:\Users\nick\Dropbox\nicks crap\teensy stuff\Arduino\hardware\teensy\avr\cores\teensy3/Print.h:42:13: warning: left operand of comma operator has no effect [-Wunused-value]
    #define HEX 16
    ^
    matix_enc_fader_midi_motori2c.ino:127:91: note: in expansion of macro 'HEX'

    Sketch uses 26,340 bytes (10%) of program storage space. Maximum is 262,144 bytes.
    Global variables use 6,240 bytes (9%) of dynamic memory, leaving 59,296 bytes for local variables. Maximum is 65,536 bytes.
    Code:
    #include <Bounce.h>
    #include <Encoder.h>
    #include <MIDI.h>
    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>
    
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
    
    const byte fader0 = 22;
    const byte pot = 23;
    const byte reciverA = 5;
    const byte reciverB = 6;
    const byte reciverC = 7;
    const byte transmitA = 2;
    const byte transmitB = 3;
    const byte transmitC = 4;
    const byte button0 = 14;
    int led = 13;
    Encoder myEnc0(9, 8);
    
    int i = 0;
    int fader00 = 0;
    int fader01 = 0;
    int newfader00 = 0;
    int newfader01 = 0;
    char channelnum = 0;
    char channelloc = 0;
    char oldchannelloc = 0;
    double faderMax = 1004;
    double faderMin = 10;
    
    
    Bounce bp14r0c0 = Bounce(button0, 20);
    Bounce bp14r0c7 = Bounce(button0, 20);
    Bounce bp14r7c0 = Bounce(button0, 20);
    Bounce bp14r7c7 = Bounce(button0, 20);
    
    void setup() {
      pwm.begin();
      pwm.setPWMFreq(1600);  // This is the maximum PWM frequency
      //  uint8_t twbrbackup = TWBR;
      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);
    }
    long old0Enc0 = -999;
    long old1Enc0 = -999;
    
    void loop() {
      usbMIDI.read();
      for (i = 0; i <= 63; i++) {
        {
          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) {
          fader00 = analogRead(fader0);
          bp14r0c0.update();
        }
        if (i == 7) {
          bp14r7c0.update();
        }
        if (i == 8) {
          fader01 = analogRead(fader0);
        }
        if (i == 56) {
          bp14r0c7.update();
        }
        if (i == 63) {
          bp14r7c7.update();
        }
      }
      if (bp14r0c0.risingEdge()) {
        usbMIDI.sendNoteOn(0, 127, 1);
      }
      if (bp14r7c0.risingEdge()) {
        usbMIDI.sendNoteOn(1, 127, 1);
      }
      if (bp14r0c7.risingEdge()) {
        usbMIDI.sendNoteOn(2, 127, 1);
      }
      if (bp14r7c7.risingEdge()) {
        usbMIDI.sendNoteOn(3, 127, 1);
      }
      if (bp14r0c0.fallingEdge()) {
        usbMIDI.sendNoteOn(0, 0, 1);
      }
      if (bp14r7c0.fallingEdge()) {
        usbMIDI.sendNoteOn(1, 0, 1);
      }
      if (bp14r0c7.fallingEdge()) {
        usbMIDI.sendNoteOn(2, 0, 1);
      }
      if (bp14r7c7.fallingEdge()) {
        usbMIDI.sendNoteOn(3, 0, 1);
      }
    
      long newEnc0;
      newEnc0 = myEnc0.read();
      if ((newEnc0 / 4) > (old0Enc0 / 4)) {
        if ((old0Enc0 / 4) == (old1Enc0 / 4)) {
          usbMIDI.sendNoteOn(1, 127, 5);
          delayMicroseconds(5);
          usbMIDI.sendNoteOff(1, 0, 5);
        }
      }
      if ((newEnc0 / 4) < (old0Enc0 / 4)) {
        if ((old0Enc0 / 4) == (old1Enc0 / 4)) {
          usbMIDI.sendNoteOn(2, 127, 5);
          delayMicroseconds(5);
          usbMIDI.sendNoteOff(2, 0, 5);
        }
      }
      if (fader00 > 1) {                                                          //*******************************************
        byte fader00send[] = {0xf0, 0x7f, 0x70, 0x02, 0x7f, 0x06, 0x00, 0x01, 0x3f, (fader00, HEX), 0xf7};
        usbMIDI.sendSysEx(11, fader00send);
      }
      if (fader01 > 1) {
        usbMIDI.sendNoteOn(61, (fader01 * 0.125), 2);
      }
      if (usbMIDI.getType() == 7 && usbMIDI.getSysExArray()[5] == 6 && oldchannelloc != usbMIDI.getSysExArray()[6]) {
        channelnum = usbMIDI.getSysExArray()[6];
        channelloc = usbMIDI.getSysExArray()[9];
      }
      oldchannelloc = channelloc;
    
      if (channelnum == 1) {      //midi in to move faders
        newfader01 = map(channelloc, 0, 127, 0, 1014);
      }
    
      if (newfader01 < fader01 - 15 && newfader01 > faderMin) {
        pwm.setPWM(0, 4096, 0);
      }
      if (newfader01 > fader01 - 15) {
        pwm.setPWM(0, 0, 0);
      }
      if (newfader01 > fader01 + 15 && newfader01 < faderMax) {
        pwm.setPWM(1, 4096, 0);
      }
      if (newfader01 < fader01 + 15) {
        pwm.setPWM(1, 0, 0);
      }
    
      old1Enc0 = old0Enc0;
      old0Enc0 = newEnc0;
    }

    when i read though the report is says #define HEX 16 in it so i add it and then gives me this

    Using library Adafruit_PWMServoDriver in folder: C:\Users\nick\Documents\Arduino\libraries\Adafruit _PWMServoDriver (1.0.x format)
    matix_enc_fader_midi_motori2c.ino: In function 'void loop()':
    matix_enc_fader_midi_motori2c.ino:6:13: warning: left operand of comma operator has no effect [-Wunused-value]
    matix_enc_fader_midi_motori2c.ino:128:91: note: in expansion of macro 'HEX'

    Sketch uses 26,340 bytes (10%) of program storage space. Maximum is 262,144 bytes.
    Global variables use 6,240 bytes (9%) of dynamic memory, leaving 59,296 bytes for local variables. Maximum is 65,536 bytes.
    a lot less problems. but i dont no what it means by 6:13: left operand of comma operator has no effect (line 6 is where i added the #define HEX 16)

    and dont no what it means by 128:91: note: in expansion of macro 'HEX'

    im yet to upload this code to the teensy yet as im doing stupid long hrs at work due to easter (On that note HAPPY EASTER every one!!!)

    will try tomorrow if i get time but any help about this will be awesome.

  23. #48
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey every one,

    i have worked out that sending midi SysEx wasnt the way to go but the way i had started to go with sending midi notes.
    as far as i have tested it is all working!!! yay. now to work on the eagle cad of it so i can get the proto type going

    Code:
    #include <Bounce.h>
    #include <Encoder.h>
    #include <MIDI.h>
    #include <Wire.h>
    #include <Adafruit_PWMServoDriver.h>
    
    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
    
    const byte touch0 = 0;
    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);
    const byte led = 13;
    const byte fader0 = 22;
    
    char i = 0;
    unsigned char fader00 = 0;
    unsigned char fader01 = 0;
    unsigned char touch00 = 0;
    unsigned char touch01 = 0;
    unsigned char newfader00 = 0;
    unsigned char newfader01 = 0;
    char channelnum = 0;
    char channelloc = 0;
    char oldchannelloc = 0;
    char newEnc0 = 0;
    char old0Enc0 = -127;
    char old1Enc0 = -127;
    
    Bounce bp14r0c0 = Bounce(button0, 20);
    Bounce bp14r0c7 = Bounce(button0, 20);
    Bounce bp14r7c0 = Bounce(button0, 20);
    Bounce bp14r7c7 = Bounce(button0, 20);
    
    void setup() {
      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++) {
        {
          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) {
          fader00 = analogRead(fader0) * 0.125;
          touch00 = touchRead(touch0);
          bp14r0c0.update();
        }
        if (i == 7) {
          bp14r7c0.update();
        }
        if (i == 8) {
          fader01 = analogRead(fader0) * 0.125;
          touch01 = touchRead(touch0);
        }
        if (i == 56) {
          bp14r0c7.update();
        }
        if (i == 63) {
          bp14r7c7.update();
        }
      }
      if (bp14r0c0.risingEdge()) {
        usbMIDI.sendNoteOn(0, 127, 1);
      }
      if (bp14r7c0.risingEdge()) {
        usbMIDI.sendNoteOn(1, 127, 1);
      }
      if (bp14r0c7.risingEdge()) {
        usbMIDI.sendNoteOn(2, 127, 1);
      }
      if (bp14r7c7.risingEdge()) {
        usbMIDI.sendNoteOn(3, 127, 1);
      }
      if (bp14r0c0.fallingEdge()) {
        usbMIDI.sendNoteOff(0, 0, 1);
      }
      if (bp14r7c0.fallingEdge()) {
        usbMIDI.sendNoteOff(1, 0, 1);
      }
      if (bp14r0c7.fallingEdge()) {
        usbMIDI.sendNoteOff(2, 0, 1);
      }
      if (bp14r7c7.fallingEdge()) {
        usbMIDI.sendNoteOff(3, 0, 1);
      }
    
      newEnc0 = myEnc0.read();
      if ((newEnc0 / 4) > (old0Enc0 / 4)) {
        if ((old0Enc0 / 4) == (old1Enc0 / 4)) {
          usbMIDI.sendNoteOn(1, 127, 5);
          delayMicroseconds(5);
          usbMIDI.sendNoteOff(1, 0, 5);
        }
      }
      if ((newEnc0 / 4) < (old0Enc0 / 4)) {
        if ((old0Enc0 / 4) == (old1Enc0 / 4)) {
          usbMIDI.sendNoteOn(2, 127, 5);
          delayMicroseconds(5);
          usbMIDI.sendNoteOff(2, 0, 5);
        }
      }
      if (touch00 > 210) {
        if (fader00 > 1) {
          usbMIDI.sendNoteOn(60, (fader00), 2);
        }
      }
      if (touch01 > 210) {
        if (fader01 > 1) {
          usbMIDI.sendNoteOn(61, (fader01), 2);
        }
      }
      if (usbMIDI.getType() == 7 && usbMIDI.getSysExArray()[5] == 6 && oldchannelloc != usbMIDI.getSysExArray()[6]) {
        channelnum = usbMIDI.getSysExArray()[6];
        channelloc = usbMIDI.getSysExArray()[9];
      }
      oldchannelloc = channelloc;
    
      if (channelnum == 1) {      //midi in to move faders
        newfader01 = map(channelloc, 0, 127, 0, 1014);
      }
      if (touch01 < 210) {
        if (newfader01 < fader01 - 15 && newfader01 > 10) {
          pwm.setPWM(0, 4096, 0);
        }
        if (newfader01 > fader01 - 15) {
          pwm.setPWM(0, 0, 0);
        }
        if (newfader01 > fader01 + 15 && newfader01 < 1014) {
          pwm.setPWM(1, 4096, 0);
        }
        if (newfader01 < fader01 + 15) {
          pwm.setPWM(1, 0, 0);
        }
      }
      old1Enc0 = old0Enc0;
      old0Enc0 = newEnc0;
    }

  24. #49
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    hey all!!

    have no idea if any1 is reading theses any more.

    but anyway. everything is working.... almost!

    1st prob: when teensy is sending midi and the program its talking too isnt sending midi every thing works the way it should. even when teensy is only reading and not sending midi everything works fine. at any speed that i more the fader

    the program i am using always sends where the fader has moved to when using midi out. so when the teensy sends midi on where the fader is it then gets it back. but when i move the fader fast the midi from the teensy starts to glich and donst send the all of the midi as to where it is so the fader on the program isnt where it should be.

    im thinking it is running out of memory? any ideas how to fix??

    2nd prob: when i let go of the fader it does a lil bounce (most likey a side affect of the 1st prob)

    3rd prob: motors!!! i have finely worked out how to adjust the speed!!! yay. atm the code has all 5 motors moving there slowest b4 they hardly move. what i would like to do is have them move full speed but when they get close to target they slow down so that they dont over shoot.

    4th prob: fader 4 and 5 are not leaving there motors off when they are touched so they can be moved without force or killing the motors. but i cant see in the code why they are the only 2 out of 5 doing it.

    ** 4th prob solved: when copying the 1st fader to 4 and 5 i forgot to change the ftouched from fader 1 to 4 and 5**


    any help will be fantastic!!!!



    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;
    }
    Last edited by Nick1802; 06-28-2015 at 02:23 AM. Reason: solved prob 4

  25. #50
    Member
    Join Date
    Feb 2014
    Location
    australia
    Posts
    83
    i had asked the above question in a new thread https://forum.pjrc.com/threads/29079...idi-and-memory

    the problem buffer problem i had has now been solved. thank you Paul and thank you everyone else that has helped me get though this project.

    so now that the prototype is now complete i am going to start prep for the full size now with 15 faders 4 endless encoder wheels and over 100 buttons.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •