Skip to content

Touch Sensor

The Touch sensor class provides access to a touch panel controller.

Creates a new Touch object instance.

Touch(options)

options

An object of properties used to construct the class.

sensor - The hardware connection definition.

interval (optional) - The sampling interval in milliseconds.

Returns an array of touch objects or undefined if no touch is in progress.

sample()

An array of objects, each containing:

x - A number indicating the X coordinate of the touch point.

y - A number indicating the Y coordinate of the touch point.

id - A number indicating which touch point this entry corresponds to.

const sensor = new device.sensor.Touch({
sensor: {
io: device.io.I2C,
address: 0x38
}
});
const sample = sensor.sample();
if (sample) {
sample.forEach(touch => {
console.log(`Touch ${touch.id} at (${touch.x}, ${touch.y})`);
});
}

Touch