Touch Sensor
The Adafruit MPR121 Gator is a 12-channel capacitive touch sensor based on the MPR121 chip. Each of the twelve pads independently detects touch and release, making it suitable for buttons, sliders, or any conductive surface. See the Adafruit learn guide for wiring and hardware details.
Connection
Call startTouchSensor() inside preload(). The device is ready to use by the time setup() runs.
let touch;
function preload() {
touch = startTouchSensor(name?, addressOrIndex?);
}name string | false | null "touchSensor"
Controls automatic event callback registration. Any function on the sketch named name + EventName (event name capitalised) is called whenever that event fires. With the default name:
function touchSensorPressed(event) { /* pad touched */ }
function touchSensorReleased(event) { /* pad released */ }Pass false or null to disable automatic registration and use addEventListener instead.
addressOrIndex number 0x5A
The I2C address of the device, or an index (0–1) into the address list. Two addresses are available, set by the ADDR pin on the board:
| Address | Index | ADDR pin |
|---|---|---|
| 0x5A | 0 | open |
| 0x5B | 1 | closed |
Methods
isPressed(sensorId) boolean
Returns true if the pad at sensorId (0–11) is currently being touched.
Methods (BaseDevice)
connect() Promise<Response>
Opens the USB connection and sends the start command to the firmware. Calling it multiple times is safe — subsequent calls return the same promise. In p5.js you do not need to call this manually; startXxx() calls it for you inside preload().
Properties
Properties (BaseDevice)
id { type, address }
Identifies the device. type is the DeviceType enum value, address is the I2C address the device was started with.
isConnected boolean
true once the USB connection has been established and the firmware has acknowledged the device. In p5.js this is always true by the time setup() runs, because startXxx() waits for the connection inside preload().
Events
pressed(event) pressed
Fires when any pad is touched. event.detail.sensorId identifies which pad.
released(event) released
Fires when a touched pad is released. event.detail.sensorId identifies which pad.
Event Argument
All event callbacks receive a single event argument. The event detail is available at event.detail and contains:
event.detail.isPressed boolean — true for a pressed event, false for a released event.
event.detail.sensorId number — The index of the pad that was touched or released (0–11).