The Proximity Trinkey makes a terrific MIDI controller you can easily add to your laptop music setup!

USB MIDI sends either a CC (continuous controller) value from 0-127 based on proximity to a mod function of your choosing, or a pitchbend value from 8192-16383.


The APDS9960 library is already built into CircuitPython for the Proximity Trinkey, as are the NeoPixel, usb_midi, and touchio libraries. However, you'll need to manually load the MIDI and register libraries.

Click the Download Project Bundle button below to download the necessary library dependency and the file in a zip file. Extract the contents of the zip file.

From inside the lib/ folder in the Project Bundle, copy the adafruit_register/ and adafruit_midi/ folders to the /lib folder on your CIRCUITPY drive.

Then, copy the file to your CIRCUITPY drive.

Your CIRCUITPY drive contents should resemble the image.

You should have in / of the CIRCUITPY drive:


And in the lib folder on your CIRCUITPY drive:

  • adafruit_midi/
  • adafruit_register/

NOTE: if you run out of space while copying the libraries to your CIRCUITPY drive, try using CircUp instead of the graphical UI of your operating system!

# SPDX-FileCopyrightText: 2021 John Park for Adafruit Industries
# SPDX-License-Identifier: MIT
Proximity Trinkey MIDI
Touch pads switch between CC and Pitch Bend modes
Blue LED for CC, Red LED for pitchbend
Brightness of LEDs for proximity
import board
import neopixel
import touchio
import usb_midi
import adafruit_midi
from adafruit_midi.control_change import ControlChange
from adafruit_midi.pitch_bend import PitchBend

from adafruit_apds9960.apds9960 import APDS9960

i2c = board.I2C()  # uses board.SCL and board.SDA
# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
apds = APDS9960(i2c)
apds.enable_proximity = True

touch1 = touchio.TouchIn(board.TOUCH1)
touch2 = touchio.TouchIn(board.TOUCH2)

pixels = neopixel.NeoPixel(board.NEOPIXEL, 2)

midi = adafruit_midi.MIDI(
    midi_in=usb_midi.ports[0], in_channel=0, midi_out=usb_midi.ports[1], out_channel=0

CC_NUM = 46  # pick your midi cc number here

def map_range(in_val, in_min, in_max, out_min, out_max):
    return out_min + ((in_val - in_min) * (out_max - out_min) / (in_max - in_min))

pixels[0] = 0x000000
pixels[1] = 0x0000FF

prox_pitch = 8192
last_prox_pitch = prox_pitch
prox_cc = 0
last_prox_cc = prox_cc
prox_bright = 0
last_prox_bright = prox_bright

mode = True

while True:

    if touch1.value:  # CC mode
        pixels[0] = 0xBB0000
        pixels[1] = 0x0
        mode = False

    if touch2.value:  # pitch bend mode
        pixels[0] = 0x0
        pixels[1] = 0x0000FF
        mode = True

    if mode:
        prox_cc = int(map_range(apds.proximity, 0, 255, 0, 127))
        if last_prox_cc is not prox_cc:
            midi.send(ControlChange(CC_NUM, prox_cc ))
            print("CC is", prox_cc)
            last_prox_cc = prox_cc
        prox_pitch = int(map_range(apds.proximity, 0, 255, 8192, 16383))
        if last_prox_pitch is not prox_pitch:
            print("Pitch bend is", prox_pitch)
            last_prox_pitch = prox_pitch

    prox_bright = map_range(apds.proximity, 0, 255, 0.01, 1.0)
    pixels.brightness = prox_bright

Use It

To test the controller, plug it into your computer and launch this handy Chrome browser MIDI Monitor web app to check that it is working.

MIDI messages are fun to look at, but even better when the make some sound! Use a software synthesizer that accepts MIDI messages (pretty much all of them do!).

Here are some examples of free, open source synths for Linux, Windows, and mac os:  

Launch your software synth and select the ProxLight Trinkey CircuitPython board as your MIDI source.

Then, assign MIDI CC 46 (you can edit the CircuitPython file to pick a different MIDI CC number if you like) to a parameter and have fun!

Tap the cap switch pads to change to pitchbend mode and get all theremin-ish up in there.

This guide was first published on Sep 29, 2021. It was last updated on Jun 15, 2024.

This page (Proximity MIDI Controller) was last updated on Jun 15, 2024.

Text editor powered by tinymce.