Midi Controller (1 potentiometer + 1 capacity sensor)

Status
Not open for further replies.

musiquemeuble

Active member
hello guys !

I'm new here and I really enjoy Teensy.
I'm building a midi controller with 2 CC messages for Ableton with Teensy 3.5. My project is to have 1 potentiometer + 1 proximity sensor. I have no problem with the potentiometer, but I don't know how to include the proximity sensor to the code. I've found CapacitiveSensor library which is great, but I can only find for Serial, and not for midi CC. I have several resistor in my possession (1Mohm / 10Mohm / 22 Mohm)

Can you help me with that?

Here is the actual code

Code:
/* USB MIDI AnalogControlChange Example

   You must select MIDI from the "Tools > USB Type" menu
   http://www.pjrc.com/teensy/td_midi.html

   This example code is in the public domain.
*/

#include <Bounce.h>

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

// the MIDI continuous controller for each analog input
const int controllerA0 = 10; // 10 = pan position

void setup()
{ 
}

// store previously sent values, to detect changes
int previousA0 = -1;

elapsedMillis msec = 0;

void loop() {
  // only check the analog inputs 50 times per second,
  // to prevent a flood of MIDI messages
  if (msec >= 20) {
    msec = 0;
    int n0 = analogRead(A0) / 8;
    // only transmit MIDI messages if analog input changed
    if (n0 != previousA0) {
      usbMIDI.sendControlChange(controllerA0, n0, channel);
      previousA0 = n0;
    }
  }

  // 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
  }
}
 
The capacitive sensing using resistors works on older, outdated AVR processors like Arduino UNO, Teensy2, etc.

The more modern Teensy3 ARM processors have a TSI (Touch sense interface) which allows to read the attached capacitance to a pin directly with the touchRead() function, with abusing another pin and a resistor to generate a trigger pulse.
 
I would say yes, go with a TSI capable Teensy 3.2 or 3.6. The TSI engine is much more reliable. The touchRead() function is already not bad, but you can optimize everything and adapt to your needs, writing directly to the TSI registers instead, to optimize reading time and resolution for example. The TSI is also interrupt and DMA capable which allows continuous readings without eating up too much CPU cycles.
 
Status
Not open for further replies.
Back
Top