Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Midi Controller (1 potentiometer + 1 capacity sensor)

  1. #1

    Midi Controller (1 potentiometer + 1 capacity sensor)

    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

    /* USB MIDI AnalogControlChange Example
       You must select MIDI from the "Tools > USB Type" menu
       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.
      while ( {
        // ignore incoming messages

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Colmar, France
    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.

  3. #3

    Thanks. I have a Teensy 3.5 and it has not a TSI. Do you think it is better to go with 3.6 for this project ?

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Colmar, France
    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.

  5. #5
    Cool ! Thanks

Posting Permissions

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