Capacitive Touch Slider (CAP1203) Hookup Guide

Pages
Contributors: andreadevo
Favorited Favorite 2

Arduino Library

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

We've provided a library to help you easily control and configure your Capacitive Touch Slider. You can download the library by searching 'SparkFun Qwiic Capacitive Touch Slider' in the Arduino library manager. Some of the features include reading when a pad is touched, detecting right and left swipes, enabling a power button, and setting the sensitivity for your own touch pads. You can also manually install the library by clicking the button below to get the library from it's GitHub repository. We have provided seven different example sketches to help you get started.

Library Functions

The Arduino library is commented and the functions should be self explanatory. However, below is a detailed list of the available library functions.

Note: It is recommended that users begin with the examples in the following section before diving head first into the library functions. The library examples demonstrate how to setup the more basic features of the Capacitive Touch Slider without having to dig through the datasheet. Once users have become familiar with the basic setups and have gone through the datasheet thoroughly, it should be easier to follow the library functions below.

Initialization Settings: We use these to set-up and initialize the board.

.begin() - Initialize the sensor, returns true if correctly set-up

.isConnected() - Checks I2C connection, returns true if correctly connected

Sensitivity Settings: These functions allow you to change the sensitivity settings for your touch pads. Note, the default sensitivity is set to SENSITIVITY_2X in the .begin() function for the SparkFun Capacitive Touch Slider board. We only recommend changing the sensitivity setting if you are breaking out your own touch pads.

.setSensitivity(sensitivity) - Sets the sensitivity multiplier for the touch pads Possible sensitivity argument values:
SENSITIVITY_128X - Most sensitive
SENSITIVITY_64X
SENSITIVITY_32X
SENSITIVITY_16X
SENSITIVITY_8X
SENSITIVITY_4X
SENSITIVITY_2X
SENSITIVITY_1X - Least sensitive

.getSensitivity() - Returns the sensitivity multiplier for the current sensitivity settings, returns as an integer value

Power Button Settings: These functions allow you to enable or disable the power button on a specific pad. The power button requires a longer touch before registering a touch has been detected on the designated pad. Note, when the power button is enabled, the designated pad will only act as the power button.

.setPowerButtonPad(pad) - Sets a button to act as a power button, returns true if correctly set Possible pad argument values:
PAD_LEFT - Left pad and CS1 breakout pin
PAD_MIDDLE - Middle pad and CS2 breakout pin
PAD_RIGHT - Right pad and CS3 breakout pin

.getPowerButtonPad() - Returns which pad is currently set to be the power button, returns as an integer value Return values:
1 - Left pad and CS1 breakout pin
2 - Middle pad and CS2 breakout pin
3 - Right pad and CS3 breakout pin

.setPowerButtonTime(time) - Sets the power button touch time, returns true if correctly set Possible time argument values:
PWR_TIME_280_MS
PWR_TIME_560_MS
PWR_TIME_1120_MS
PWR_TIME_2240_MS

.getPowerButtonTime() - Returns length of time (ms) power button must indicate a touch, returns as an integer value

.setPowerButtonEnabled() - Enables power button functionality
.setPowerButtonDisabled() - Disables power button functionality

isPowerButtonEnabled() - Returns true if power button functionality is currently enabled

Interrupt Settings: These functions allow you to control if the interrupt pin is enabled. When enabled, the green interrupt LED will turn on when any pad detects a touch. Note, the interrupt is enabled as default in the .begin() function.

.setInterruptDisabled() - Disables interrupt pin
.setInterruptEnabled() - Enables interrupt pin

.isInterruptEnabled() - Returns true if interrupt pin is currently enabled

Check if a capacitive touch pad or breakout pin has been touched: These functions allow you to check when a capacitive touch pad or breakout pin has been touched.

.isLeftTouched() - Returns true if left pad or CS1 pin detects a touch
.isMiddleTouched() - Returns true if middle pad or CS2 pin detects a touch
.isRightTouched() - Returns true if right pad or CS3 pin detects a touch
.isTouched() - Returns true if any pad or breakout pin detects a touch
.isPowerButtonTouched() - Returns true if designated power button pad or pin held for alloted time

Check if a swipe has occured: The direction of the swipe is relative to the arrow on the board pointing in the right direction. For the pins, a right swipe is first CS1, then CS2, and finally CS3 and a left swipe is first CS3, then CS2, and finally CS1. Note, these functions pull most available resources. For best swipe recognition, we highly recommend not implementing other functionalities when using these two functions.

.isRightSwipePulled() - Returns true if board detects a right swipe
.isLeftSwipePulled() - Returns true if board detects a left swipe