Teensy LC Midi Controller for Plugins in Logic Pro X

Status
Not open for further replies.
Not sure because if I change it I get the error message: 'DIGITAL_PINS' was not declared in this scope


DIGITAL_PINS is in the line right below D_PINS

I was wondering why it was suggested to try ALL digital pins … looking again with that in mind perhaps it was expected there was a local array : DIGITAL_PINS[]

Where if you had 7 digital pins to setup:: #define D_PINS 7

and then the local array would hold the active pins in use:: uint16_t DIGITAL_PINS[ D_PINS ] = { 3,4,7,8,20,21,33 };

Then that loop would quickly set them all with pinmode as shown.
 
Hey, sorry for the late response but I have been busy lately. However, I tried doing what you wrote but can't manage to make it work.
The VU meter bounces a few times but then nothing happens. The midi works perfectly though.

Here's the code when modded:
Code:
//************LIBRARIES USED**************
// include the ResponsiveAnalogRead library for analog smoothing
#include <ResponsiveAnalogRead.h>
// include the Bounce library for 'de-bouncing' switches -- removing electrical chatter as contacts settle
#include <Bounce.h> 
//usbMIDI.h library is added automatically when code is compiled as a MIDI device
#include "Wire.h"
#define D_PINS 9

// ******VU METER******
int leftMeter = 20;       // left meter (hours) is attached to pin 20 (PWM)
int leftChannel = 0;     // left channel of audio (analog 4)
int sensitivity = 0;     // 10k pot sensitivity control (analog 8)
int leftLevel = 0;       // position of the left meter 


// ******CONSTANT VALUES******** 
// customize code behaviour here!
const int channel = 1; // MIDI channel
const int A_PINS = 4; // number of Analog PINS
const int ON_VELOCITY = 99; // note-one velocity sent from buttons (should be 65 to  127)

// define the pins you want to use and the CC ID numbers on which to send them..
const int ANALOG_PINS[A_PINS] = {A0,A1,A2,A3};
const int CCID[A_PINS] = {21,22,23,24};

// define the pins and notes for digital events
uint16_t DIGITAL_PINS[D_PINS] = {0,1,2,3,4,5,6,7,8};
const int note[D_PINS] = {60,61,62,63,64,65,66,67,68};
const int BOUNCE_TIME = 15; // 5 ms is usually sufficient
const boolean toggled = true;


//******VARIABLES***********
// a data array and a lagged copy to tell when MIDI changes are required
byte data[A_PINS];
byte dataLag[A_PINS]; // when lag and new are not the same then update MIDI CC value


//************INITIALIZE LIBRARY OBJECTS**************
// not sure if there is a better way... some way run a setup loop on global array??
// use comment tags to comment out unused portions of array definitions

// initialize the ReponsiveAnalogRead objects
ResponsiveAnalogRead analog[]{
  {ANALOG_PINS[0],true},
  {ANALOG_PINS[1],true},
  {ANALOG_PINS[2],true},
  {ANALOG_PINS[3],true}/*,
  {ANALOG_PINS[4],true},
  {ANALOG_PINS[5],true},
  {ANALOG_PINS[6],true},
  {ANALOG_PINS[7],true},
  {ANALOG_PINS[8],true}/*,
  {ANALOG_PINS[6],true},
  {ANALOG_PINS[7],true},*/
}; 

// initialize the bounce objects 
Bounce digital[] =   {
  Bounce(DIGITAL_PINS[0], BOUNCE_TIME), 
  Bounce(DIGITAL_PINS[1], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[2], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[3], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[4], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[5], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[6], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[7], BOUNCE_TIME),
  Bounce(DIGITAL_PINS[8], BOUNCE_TIME)/*,,*/
}; 

//************SETUP**************
void setup() {
// loop to configure input pins and internal pullup resisters for digital section
  for (int i=0;i<D_PINS;i++){
    pinMode(DIGITAL_PINS[i], INPUT_PULLUP);
    
    Wire.begin();
  // Serial.begin(9600); Un-comment to view time in serial monitor
  
  pinMode(leftMeter, OUTPUT);      // Initialize Outputs 
  
  digitalWrite(leftMeter, HIGH);   // Test meters on startup
  digitalWrite(13, HIGH);
  delay (1000);
  digitalWrite(leftMeter, LOW);
  digitalWrite(13, LOW);
  delay(1000);
  }
}

//************LOOP**************
void loop() {

 sensitivity = (analogRead(A8) / 3 + 1); // potentiometer sensitivity control
{
     analogWrite(leftMeter, leftLevel); // adjust left meter level
    }
     
     leftChannel = analogRead(A4); // read left channel of audio 
   
  // Below is the code to set meter levels based on sound levels: 
  // If you change the values, remember to make sure that the Left and Right channels are matching.
  // leftLevel and rightLevel can be set from 0 to 255 (PWM)
  
    if (leftChannel >= sensitivity && leftLevel < 20){   
   leftLevel = 20; 
      }
    
    if (leftChannel >= sensitivity + 5 && leftLevel < 41){   
   leftLevel = 41;
      }
        
    if (leftChannel >= sensitivity + 10 && leftLevel < 62){   
   leftLevel = 62;
      }
      
    if (leftChannel >= sensitivity + 15 && leftLevel < 83){   
   leftLevel = 83;
      }
      
    if (leftChannel >= sensitivity + 20 && leftLevel < 104){   
   leftLevel = 104;
      }
        
    if (leftChannel >= sensitivity + 25 && leftLevel < 125){
   leftLevel = 125;
      }
    
     if (leftChannel >= sensitivity + 30 && leftLevel < 146){   
   leftLevel = 146;
      }
      
    if (leftChannel >= sensitivity + 35 && leftLevel < 167){
   leftLevel = 167;
       } 
       
    if (leftChannel >= sensitivity + 37 && leftLevel < 188){
   leftLevel = 188;
       } 
     
    if (leftChannel >= sensitivity + 40 && leftLevel < 209){
    leftLevel = 209;
       }  
       
    if (leftChannel >= sensitivity + 42 && leftLevel < 230){
    leftLevel = 230;
       }  
 
    if (leftChannel >= sensitivity + 45 && leftLevel < 255){
    leftLevel = 255;
       }

 // Fade the meters out to 0
   if (leftChannel < sensitivity && leftLevel > 0){   
     leftLevel = --leftLevel;  // left meter                       
     delayMicroseconds(1000); // can be increased and decreased to adjust smoothness 
   }                          // (how long it takes to get back to 0)
  
  getAnalogData();
  getDigitalData();
  while (usbMIDI.read()) {
     // controllers must call .read() to keep the queue clear even if they are not responding to MIDI
  }
 }


//************ANALOG SECTION**************
void getAnalogData(){  
  for (int i=0;i<A_PINS;i++){
    // update the ResponsiveAnalogRead object every loop
    analog[i].update(); 
    // if the repsonsive value has change, print out 'changed'
    if(analog[i].hasChanged()) {
      data[i] = analog[i].getValue()>>3;
      if (data[i] != dataLag[i]){
        dataLag[i] = data[i];
        usbMIDI.sendControlChange(CCID[i], data[i], channel);
      }
    }
  }
}



//************DIGITAL SECTION**************
void getDigitalData(){
  for (int i=0;i<D_PINS;i++){
  digital[i].update();
    if (digital[i].fallingEdge()) {
      usbMIDI.sendNoteOn(note[i], ON_VELOCITY, channel);  
    }
    // Note Off messages when each button is released
    if (digital[i].risingEdge()) {
      usbMIDI.sendNoteOff(note[i], 0, channel);  
    }
  }
}
 
Update! Here are some pics of the controller that I made. It was made using a box that came with a lamp from IKEA (yes Swedes love IKEA too). As you can see, one attempt to mount everything was made on the lid.. Oh, and I am about to paint the white parts in front black but haven't bought a pen for the job yet.

It works perfectly and whenever I use an 1176 on a track I reach for this instead of using the mouse. It's definitely made mixing a lot more fun! Thanks for all the help guys!

2nrenuv.jpg


swd445.jpg


21mt17t.jpg
 
Status
Not open for further replies.
Back
Top