Analog and Digital Inputs for Teensy 3.2 MIDI Programming within Arduino

Been having some trouble with programming my custom potentiometers for my midi controller. I have 12 buttons and 6 knobs. I have it wired correctly and have the sanwa arcade buttons working fine. I'm just having a huge problem adding analog code to my digital code. I'm not sure where to go from here, I have tried over 20 different types of analog code and I'm not sure what I'm doing wrong. Just need a basic potentiometer for reading MIDI. I have the first 1-12 digital inputs on my teensy soldered in for my arcade buttons. For the analog potentiometers I have them soldered on inputs 18-23 or (A4 thru A9) on the Teensy 3.2. I am using Arduino software along with the Teensy loader. Any help would be greatly appreciated, thank you.

Here is the code I have thus far. I only have the 19 and 23 analog inputs written in this one at the very end, because I removed the others. 

********

/* Buttons to USB MIDI Example

   You must select MIDI from the "Tools > USB Type" menu

   To view the raw MIDI data on Linux: aseqdump -p "Teensy MIDI"

   This example code is in the public domain.
*/

#include <Bounce.h>

// the MIDI channel number to send messages
const int channel = 1;

// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 5);  // which is appropriate for good
Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(5, 5);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 5);  // to rapid touch, you can
Bounce button7 = Bounce(7, 5);  // increase this time.
Bounce button8 = Bounce(8, 5);
Bounce button9 = Bounce(9, 5);
Bounce button10 = Bounce(10, 5);
Bounce button11 = Bounce(11, 5);
Bounce button12 = Bounce(12, 5);


void setup() {
  // Configure the pins for input mode with pullup resistors.
  // The pushbuttons connect from each pin to ground.  When
  // the button is pressed, the pin reads LOW because the button
  // shorts it to ground.  When released, the pin reads HIGH
  // because the pullup resistor connects to +5 volts inside
  // the chip.  LOW for "on", and HIGH for "off" may seem
  // backwards, but using the on-chip pullup resistors is very
  // convenient.  The scheme is called "active low", and it's
  // very commonly used in electronics... so much that the chip
  // has built-in pullup resistors!
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);  // Teensy++ 2.0 LED, may need 1k resistor pullup
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);// Teensy 2.0 LED, may need 1k resistor pullup
}

void loop() {
  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update();
  button7.update();
  button8.update();
  button9.update();
  button10.update();
  button11.update();
  button12.update();

  // Check each button for "falling" edge.
  // Send a MIDI Note On message when each button presses
  // Update the Joystick buttons only upon changes.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
  if (button1.fallingEdge()) {
    usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4
  }
  if (button2.fallingEdge()) {
    usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4
  }
  if (button3.fallingEdge()) {
    usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4
  }
  if (button4.fallingEdge()) {
    usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4
  }
  if (button5.fallingEdge()) {
    usbMIDI.sendNoteOn(65, 99, channel);  // 65 = F4
  }
  if (button6.fallingEdge()) {
    usbMIDI.sendNoteOn(66, 99, channel);  // 66 = F#4
  }
  if (button7.fallingEdge()) {
    usbMIDI.sendNoteOn(67, 99, channel);  // 67 = G4
  }
  if (button8.fallingEdge()) {
    usbMIDI.sendNoteOn(68, 99, channel);  // 68 = G#4
  }
  if (button9.fallingEdge()) {
    usbMIDI.sendNoteOn(69, 99, channel);  // 69 = A5
  }
  if (button10.fallingEdge()) {
    usbMIDI.sendNoteOn(70, 99, channel);  // 70 = A#5
  }
  if (button11.fallingEdge()) {
    usbMIDI.sendNoteOn(71, 99, channel);  // 71 = B5
  }
  if (button12.fallingEdge()) {
    usbMIDI.sendNoteOn(72, 99, channel);  // 72 = C4
  // Check each button for "rising" edge
  // Send a MIDI Note Off message when each button releases
  // For many types of projects, you only care when the button
  // is pressed and the release isn't needed.
  // rising = low (pressed - button connects pin to ground)
  //          to high (not pressed - voltage from pullup resistor)
   }
  if (button1.risingEdge()) {
    usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4
  }
  if (button2.risingEdge()) {
    usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4
  }
  if (button3.risingEdge()) {
    usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4
  }
  if (button4.risingEdge()) {
    usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4
  }
  if (button5.risingEdge()) {
    usbMIDI.sendNoteOff(65, 0, channel);  // 65 = F4
  }
  if (button6.risingEdge()) {
    usbMIDI.sendNoteOff(66, 0, channel);  // 66 = F#4
  }
  if (button7.risingEdge()) {
    usbMIDI.sendNoteOff(67, 0, channel);  // 67 = G4
  }
  if (button8.risingEdge()) {
    usbMIDI.sendNoteOff(68, 0, channel);  // 68 = G#4
  }
  if (button9.risingEdge()) {
    usbMIDI.sendNoteOff(69, 0, channel);  // 69 = A5
  }
  if (button10.risingEdge()) {
    usbMIDI.sendNoteOff(70, 0, channel);  // 70 = A#5
  }
  if (button11.risingEdge()) {
    usbMIDI.sendNoteOff(71, 0, channel);  // 71 = B5
  }
  if (button12.risingEdge()) {
    usbMIDI.sendNoteOff(72, 0, channel);  // 72 = C4
  // MIDI Controllers should discard incoming MIDI messages.
  // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
  while (usbMIDI.read()) {
    // ignore incoming messages
  }
}
// read the input on analog pin 19:
  int sensorValue = analogRead(A5);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
}
// read the input on analog pin 23:
  int sensorValue = analogRead(A9);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:



sort by: active | newest | oldest
tttapa1 month ago

Take a look at my MIDI controller library. It does exactly what you need.

abissmusic (author)  tttapa1 month ago

I just can't seem to get it to work with the code I posted above, there is always some error and I'm not a programming expert. I have tested the voltage on the knobs with the serial monitor using this code and it works. I am getting a voltage from 0 to 3.3v. That is the only thing I've gotten to work. Maybe there is voltage to midi code? Let me know if I have any errors or need to move something.

*
ReadAnalogVoltage

Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/ReadAnalogVolta...
*/

// the setup routine runs once when you press reset:
voidsetup(){
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
voidloop(){
// read the input on analog pin 0:
int sensorValue =analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue *(5.0/1023.0);
// print out the value you read:
Serial.println(voltage);
}

*****************************************

Here is my button code mixed with your potentiometer code and Im getting nothing in the signal, buttons still work. Let me know if there is any errors:

/* Buttons to USB MIDI Example

You must select MIDI from the "Tools > USB Type" menu

To view the raw MIDI data on Linux: aseqdump -p "Teensy MIDI"

This example code is in the public domain.

*/

#include <MIDI_Controller.h> // Include the library

// Create a new instance of the class 'Analog', called 'potentiometer', on pin A5,

// that sends MIDI messages with controller 7 (channel volume) on channel 1

Analog potentiometer(A5, MIDI_CC::Channel_Volume, 1);

#include <Bounce.h>

// the MIDI channel number to send messages

const int channel = 1;

// Create Bounce objects for each button. The Bounce object

// automatically deals with contact chatter or "bounce", and

// it makes detecting changes very simple.

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

Bounce button2 = Bounce(2, 5); // which is appropriate for good

Bounce button3 = Bounce(3, 5); // quality mechanical pushbuttons

Bounce button4 = Bounce(4, 5);

Bounce button5 = Bounce(5, 5); // if a button is too "sensitive"

Bounce button6 = Bounce(6, 5); // to rapid touch, you can

Bounce button7 = Bounce(7, 5); // increase this time.

Bounce button8 = Bounce(8, 5);

Bounce button9 = Bounce(9, 5);

Bounce button10 = Bounce(10, 5);

Bounce button11 = Bounce(11, 5);

Bounce button12 = Bounce(12, 5);

int val = 0; //Our initial pot values. We need one for the first value and a second to test if there has been a change made. This needs to be done for all 3 pots.

int lastVal = 0;

int val2 = 0;

int lastVal2 = 0;

void setup() {

// Configure the pins for input mode with pullup resistors.

// The pushbuttons connect from each pin to ground. When

// the button is pressed, the pin reads LOW because the button

// shorts it to ground. When released, the pin reads HIGH

// because the pullup resistor connects to +5 volts inside

// the chip. LOW for "on", and HIGH for "off" may seem

// backwards, but using the on-chip pullup resistors is very

// convenient. The scheme is called "active low", and it's

// very commonly used in electronics... so much that the chip

// has built-in pullup resistors!

pinMode(1, INPUT_PULLUP);

pinMode(2, INPUT_PULLUP);

pinMode(3, INPUT_PULLUP);

pinMode(4, INPUT_PULLUP);

pinMode(5, INPUT_PULLUP);

pinMode(6, INPUT_PULLUP); // Teensy++ 2.0 LED, may need 1k resistor pullup

pinMode(7, INPUT_PULLUP);

pinMode(8, INPUT_PULLUP);

pinMode(9, INPUT_PULLUP);

pinMode(10, INPUT_PULLUP);

pinMode(11, INPUT_PULLUP);

pinMode(12, INPUT_PULLUP);// Teensy 2.0 LED, may need 1k resistor pullup

}

void loop() {

// Update all the buttons. There should not be any long

// delays in loop(), so this runs repetitively at a rate

// faster than the buttons could be pressed and released.

button1.update();

button2.update();

button3.update();

button4.update();

button5.update();

button6.update();

button7.update();

button8.update();

button9.update();

button10.update();

button11.update();

button12.update();

// Check each button for "falling" edge.

// Send a MIDI Note On message when each button presses

// Update the Joystick buttons only upon changes.

// falling = high (not pressed - voltage from pullup resistor)

// to low (pressed - button connects pin to ground)

if (button1.fallingEdge()) {

usbMIDI.sendNoteOn(61, 99, channel); // 61 = C#4

}

if (button2.fallingEdge()) {

usbMIDI.sendNoteOn(62, 99, channel); // 62 = D4

}

if (button3.fallingEdge()) {

usbMIDI.sendNoteOn(63, 99, channel); // 63 = D#4

}

if (button4.fallingEdge()) {

usbMIDI.sendNoteOn(64, 99, channel); // 64 = E4

}

if (button5.fallingEdge()) {

usbMIDI.sendNoteOn(65, 99, channel); // 65 = F4

}

if (button6.fallingEdge()) {

usbMIDI.sendNoteOn(66, 99, channel); // 66 = F#4

}

if (button7.fallingEdge()) {

usbMIDI.sendNoteOn(67, 99, channel); // 67 = G4

}

if (button8.fallingEdge()) {

usbMIDI.sendNoteOn(68, 99, channel); // 68 = G#4

}

if (button9.fallingEdge()) {

usbMIDI.sendNoteOn(69, 99, channel); // 69 = A5

}

if (button10.fallingEdge()) {

usbMIDI.sendNoteOn(70, 99, channel); // 70 = A#5

}

if (button11.fallingEdge()) {

usbMIDI.sendNoteOn(71, 99, channel); // 71 = B5

}

if (button12.fallingEdge()) {

usbMIDI.sendNoteOn(72, 99, channel); // 72 = C4

// Check each button for "rising" edge

// Send a MIDI Note Off message when each button releases

// For many types of projects, you only care when the button

// is pressed and the release isn't needed.

// rising = low (pressed - button connects pin to ground)

// to high (not pressed - voltage from pullup resistor)

}

if (button1.risingEdge()) {

usbMIDI.sendNoteOff(61, 0, channel); // 61 = C#4

}

if (button2.risingEdge()) {

usbMIDI.sendNoteOff(62, 0, channel); // 62 = D4

}

if (button3.risingEdge()) {

usbMIDI.sendNoteOff(63, 0, channel); // 63 = D#4

}

if (button4.risingEdge()) {

usbMIDI.sendNoteOff(64, 0, channel); // 64 = E4

}

if (button5.risingEdge()) {

usbMIDI.sendNoteOff(65, 0, channel); // 65 = F4

}

if (button6.risingEdge()) {

usbMIDI.sendNoteOff(66, 0, channel); // 66 = F#4

}

if (button7.risingEdge()) {

usbMIDI.sendNoteOff(67, 0, channel); // 67 = G4

}

if (button8.risingEdge()) {

usbMIDI.sendNoteOff(68, 0, channel); // 68 = G#4

}

if (button9.risingEdge()) {

usbMIDI.sendNoteOff(69, 0, channel); // 69 = A5

}

if (button10.risingEdge()) {

usbMIDI.sendNoteOff(70, 0, channel); // 70 = A#5

}

if (button11.risingEdge()) {

usbMIDI.sendNoteOff(71, 0, channel); // 71 = B5

}

if (button12.risingEdge()) {

usbMIDI.sendNoteOff(72, 0, channel); // 72 = C4

// MIDI Controllers should discard incoming MIDI messages.

// http://forum.pjrc.com/threads/24179-Teensy-3-Able...

while (usbMIDI.read()) {

// ignore incoming messages

}

{

// Refresh the MIDI controller (check whether the potentiometer's input has changed since last time, if so, send the new value over MIDI)

MIDI_Controller.refresh();

}

}}

Use CTRL+T (Autoformat) in the Arduino IDE to see what's going on with your curly braces.

Your problem is that MIDI_Controller.refresh() is inside of the final if-clause (if (button12.risingEdge())), which means that you only send the analog values when button 12 is released. Just move it outside of that if-clause.

Why are you using the extremely inflated code for the buttons when you can just use the MIDI controller library? It does exactly the same thing as your code, including debouncing.

Or if you don't want to use the library, at least try to use for-loops and arrays to condense the code and make it more readable.

You should also fix your noteOff events: a note off with a velocity of zero is not defined. Just make it maximum velocity (127).

Also note that the Teensy 3.2 is a 3.3V device, so the analog range is [0V, 3.3V], not [0V, 5V]. However, absolute voltages don't matter in this case, you just need to know the position of the potentiometers. As long as the ADC reference voltage is the same as the voltage on the potentiometer's right pin, you don't have to worry about the absolute voltage.

This would be your code using the MIDI Controller library:

<pre>#include <MIDI_Controller.h> // Include the library
const uint8_t velocity = 0b1111111; // Maximum velocity (0b1111111 = 0x7F = 127)
const uint8_t channel = 1; // MIDI channel 1
// Create an array of 12 new instances of the class 'Digital', called 'buttons',
// on pins 1, 2, ..., 12 that send MIDI messages with notes
// 61, 62, ..., 72 on MIDI channel 1, with maximum velocity (127)
Digital buttons[] = {
{ 1, 61, channel, velocity }, // button connected to pin 1, sends MIDI note 61 (C#3) on channel 1 with velocity 127
{ 2, 62, channel, velocity },
{ 3, 63, channel, velocity },
{ 4, 64, channel, velocity },
{ 5, 65, channel, velocity },
{ 6, 66, channel, velocity },
{ 7, 67, channel, velocity },
{ 8, 68, channel, velocity },
{ 9, 69, channel, velocity },
{10, 70, channel, velocity },
{11, 71, channel, velocity },
{12, 72, channel, velocity },
};
// Create an array of 6 new instances of the class 'Analog', called 'potentiometers',
// on pins A0, A1, .., A5 that send MIDI CC messages with controller numbers 16, 17, ... 21
// on MIDI channel 1
Analog potentiometers[] = {
{ A0, 16, channel }, // potentiometer connected to pin A0, sends CC (Control Change) #16 on MIDI channel 1
{ A1, 17, channel },
{ A2, 18, channel },
{ A3, 19, channel },
{ A4, 20, channel },
{ A5, 21, channel },
};
void setup() {} // nothing to set up
void loop() { // Refresh the buttons and potentiometers (check whether a button's state or a potentiometer's position has changed since last time, if so, send it over MIDI)
MIDI_Controller.refresh();
}</pre>
abissmusic (author)  tttapa1 month ago

This midi controller design programming is all very new to me. I'm barely getting by. So please bare with me if you can. I have successfully finally got one potentiometer to work using your Ex. 1 - Potentiometer code from your midi controller bank and binded it in Ableton and it works for midi. The reason I am still using the long drawn out inflated code thus far for the buttons, is because that is literally the only code that works for my buttons. I tried the code you posted above and changed the values for the input pins, but somehow I am still getting an error. Now that I have got one potentiometer to work with my buttons how can I edit this code to add more potentiometers? Thank you.

/*

This is an example of the "Analog" class of the MIDI_controller library.

Connect a potentiometer to analog pin A0. This will be the MIDI channel volume of channel 1.

Map it in your DAW or DJ software.

Written by Pieter P, 08-09-2017

https://github.com/tttapa/MIDI_controller

*/

#include <MIDI_Controller.h> // Include the library

// Create a new instance of the class 'Analog', called 'potentiometer', on pin A0,

// that sends MIDI messages with controller 7 (channel volume) on channel 1

Analog potentiometer(A9, MIDI_CC::Channel_Volume, 1);

#include <Bounce.h>

// the MIDI channel number to send messages

const int channel = 1;

// Create Bounce objects for each button. The Bounce object

// automatically deals with contact chatter or "bounce", and

// it makes detecting changes very simple.

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

Bounce button2 = Bounce(2, 5); // which is appropriate for good

Bounce button3 = Bounce(3, 5); // quality mechanical pushbuttons

Bounce button4 = Bounce(4, 5);

Bounce button5 = Bounce(5, 5); // if a button is too "sensitive"

Bounce button6 = Bounce(6, 5); // to rapid touch, you can

Bounce button7 = Bounce(7, 5); // increase this time.

Bounce button8 = Bounce(8, 5);

Bounce button9 = Bounce(9, 5);

Bounce button10 = Bounce(10, 5);

Bounce button11 = Bounce(11, 5);

Bounce button12 = Bounce(12, 5);

void setup() {

// Configure the pins for input mode with pullup resistors.

// The pushbuttons connect from each pin to ground. When

// the button is pressed, the pin reads LOW because the button

// shorts it to ground. When released, the pin reads HIGH

// because the pullup resistor connects to +5 volts inside

// the chip. LOW for "on", and HIGH for "off" may seem

// backwards, but using the on-chip pullup resistors is very

// convenient. The scheme is called "active low", and it's

// very commonly used in electronics... so much that the chip

// has built-in pullup resistors!

pinMode(1, INPUT_PULLUP);

pinMode(2, INPUT_PULLUP);

pinMode(3, INPUT_PULLUP);

pinMode(4, INPUT_PULLUP);

pinMode(5, INPUT_PULLUP);

pinMode(6, INPUT_PULLUP); // Teensy++ 2.0 LED, may need 1k resistor pullup

pinMode(7, INPUT_PULLUP);

pinMode(8, INPUT_PULLUP);

pinMode(9, INPUT_PULLUP);

pinMode(10, INPUT_PULLUP);

pinMode(11, INPUT_PULLUP);

pinMode(12, INPUT_PULLUP);// Teensy 2.0 LED, may need 1k resistor pullup

}

void loop() {

// Update all the buttons. There should not be any long

// delays in loop(), so this runs repetitively at a rate

// faster than the buttons could be pressed and released.

button1.update();

button2.update();

button3.update();

button4.update();

button5.update();

button6.update();

button7.update();

button8.update();

button9.update();

button10.update();

button11.update();

button12.update();

// Check each button for "falling" edge.

// Send a MIDI Note On message when each button presses

// Update the Joystick buttons only upon changes.

// falling = high (not pressed - voltage from pullup resistor)

// to low (pressed - button connects pin to ground)

if (button1.fallingEdge()) {

usbMIDI.sendNoteOn(61, 99, channel); // 61 = C#4

}

if (button2.fallingEdge()) {

usbMIDI.sendNoteOn(62, 99, channel); // 62 = D4

}

if (button3.fallingEdge()) {

usbMIDI.sendNoteOn(63, 99, channel); // 63 = D#4

}

if (button4.fallingEdge()) {

usbMIDI.sendNoteOn(64, 99, channel); // 64 = E4

}

if (button5.fallingEdge()) {

usbMIDI.sendNoteOn(65, 99, channel); // 65 = F4

}

if (button6.fallingEdge()) {

usbMIDI.sendNoteOn(66, 99, channel); // 66 = F#4

}

if (button7.fallingEdge()) {

usbMIDI.sendNoteOn(67, 99, channel); // 67 = G4

}

if (button8.fallingEdge()) {

usbMIDI.sendNoteOn(68, 99, channel); // 68 = G#4

}

if (button9.fallingEdge()) {

usbMIDI.sendNoteOn(69, 99, channel); // 69 = A5

}

if (button10.fallingEdge()) {

usbMIDI.sendNoteOn(70, 99, channel); // 70 = A#5

}

if (button11.fallingEdge()) {

usbMIDI.sendNoteOn(71, 99, channel); // 71 = B5

}

if (button12.fallingEdge()) {

usbMIDI.sendNoteOn(72, 99, channel); // 72 = C4

// Check each button for "rising" edge

// Send a MIDI Note Off message when each button releases

// For many types of projects, you only care when the button

// is pressed and the release isn't needed.

// rising = low (pressed - button connects pin to ground)

// to high (not pressed - voltage from pullup resistor)

}

if (button1.risingEdge()) {

usbMIDI.sendNoteOff(61, 0, channel); // 61 = C#4

}

if (button2.risingEdge()) {

usbMIDI.sendNoteOff(62, 0, channel); // 62 = D4

}

if (button3.risingEdge()) {

usbMIDI.sendNoteOff(63, 0, channel); // 63 = D#4

}

if (button4.risingEdge()) {

usbMIDI.sendNoteOff(64, 0, channel); // 64 = E4

}

if (button5.risingEdge()) {

usbMIDI.sendNoteOff(65, 0, channel); // 65 = F4

}

if (button6.risingEdge()) {

usbMIDI.sendNoteOff(66, 0, channel); // 66 = F#4

}

if (button7.risingEdge()) {

usbMIDI.sendNoteOff(67, 0, channel); // 67 = G4

}

if (button8.risingEdge()) {

usbMIDI.sendNoteOff(68, 0, channel); // 68 = G#4

}

if (button9.risingEdge()) {

usbMIDI.sendNoteOff(69, 0, channel); // 69 = A5

}

if (button10.risingEdge()) {

usbMIDI.sendNoteOff(70, 0, channel); // 70 = A#5

}

if (button11.risingEdge()) {

usbMIDI.sendNoteOff(71, 0, channel); // 71 = B5

}

if (button12.risingEdge()) {

usbMIDI.sendNoteOff(72, 0, channel); // 72 = C4

// MIDI Controllers should discard incoming MIDI messages.

// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash

while (usbMIDI.read()) {

// ignore incoming messages

}

}}

abissmusic (author)  abissmusic1 month ago

To be more straight forward, I'm looking to add more potentiometers to your code below:

/*

This is an example of the "Analog" class of the MIDI_controller library.

Connect a potentiometer to analog pin A0. This will be the MIDI channel volume of channel 1.

Map it in your DAW or DJ software.

Written by Pieter P, 08-09-2017

https://github.com/tttapa/MIDI_controller

*/

#include <MIDI_Controller.h> // Include the library

// Create a new instance of the class 'Analog', called 'potentiometer', on pin A0,

// that sends MIDI messages with controller 7 (channel volume) on channel 1

Analog potentiometer(A9, MIDI_CC::Channel_Volume, 1);

-----(How to write this line of code here for the next potentiometer)-------------

Take a look at how it's done in the example I posted in my previous reply. What error are you getting? I just tried it, and it works without any problems.

abissmusic (author)  tttapa1 month ago

Ok the code you posted in your previous example works, not sure what happened before. However when I open up Ableton and click on MIDI, all of a sudden Ableton just locks up, and I have to shut it down. Any ideas why? Did I do something wrong?

When I use the code (Ex. 1 Potentiometer) everything works great and I can bind it to a fader, knob or whatever in Ableton and I can also use my buttons. Can you tell me how to write code for multiple potentiometers in the same format as that one? i.e

*/

#include <MIDI_Controller.h> // Include the library

// Create a new instance of the class 'Analog', called 'potentiometer', on pin A0,

// that sends MIDI messages with controller 7 (channel volume) on channel 1

Analog potentiometer(A9, MIDI_CC::Channel_Volume, 1);

-----(How to write this line of code here for the next potentiometer)-------------