Skip to content

Commit 98e05cb

Browse files
committed
Completed Capacitive Touch Slider Library
* Example 1 - Basic Reading * Example 2 - Detect Any Touch * Example 3 - Detect Swipe * Example 4 - Power Button * Example 5 - Detect Current Touch * Example 6 - Set Sensitivity
1 parent 1701bd0 commit 98e05cb

File tree

9 files changed

+452
-450
lines changed

9 files changed

+452
-450
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Library for the CAP1203
3+
By: Andrea DeVore
4+
SparkFun Electronics
5+
6+
Do you like this library? Help support SparkFun. Buy a board!
7+
8+
This sketch uses the SparkFun_CAP1203 library to initialize
9+
the capacitive touch sensor and stream when any pad detects
10+
a touch.
11+
12+
License: This code is public domain, but if you see me
13+
(or any other SparkFun employee) at the local, and you've
14+
found our code helpful, please buy us a round (Beerware
15+
license).
16+
17+
Distributed as is; no warrenty given.
18+
*/
19+
20+
#include <SparkFun_CAP1203_Registers.h>
21+
#include <SparkFun_CAP1203_Types.h>
22+
#include <Wire.h>
23+
24+
CAP1203 sensor; // Initialize sensor
25+
26+
void setup() {
27+
Wire.begin(); // Join I2C bus
28+
Serial.begin(9600); // Start serial for output
29+
30+
// Setup sensor
31+
if (sensor.begin() == false) {
32+
Serial.println("Not connected. Please check connections and read the hookup guide.");
33+
while (1);
34+
}
35+
else {
36+
Serial.println("Connected!");
37+
}
38+
}
39+
40+
void loop() {
41+
if (sensor.isTouched() == true) {
42+
Serial.println("Touch");
43+
}
44+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Library for the CAP1203
3+
By: Andrea DeVore
4+
SparkFun Electronics
5+
6+
Do you like this library? Help support SparkFun. Buy a board!
7+
8+
This sketch uses the SparkFun_CAP1203 library to initialize
9+
the capacitive touch sensor and notifies the user when the
10+
CAP1203 board detects a right or left swipe. Note: the two
11+
swipe functions pull most available resources for running
12+
the sensor. As such, refrain from implementing other
13+
functionality when using the swipe functions.
14+
15+
License: This code is public domain, but if you see me
16+
(or any other SparkFun employee) at the local, and you've
17+
found our code helpful, please buy us a round (Beerware
18+
license).
19+
20+
Distributed as is; no warrenty given.
21+
*/
22+
23+
#include <SparkFun_CAP1203_Registers.h>
24+
#include <SparkFun_CAP1203_Types.h>
25+
#include <Wire.h>
26+
27+
CAP1203 sensor; // Initialize sensor
28+
29+
void setup() {
30+
Wire.begin(); // Join I2C bus
31+
Serial.begin(9600); // Start serial for output
32+
33+
// Setup sensor
34+
if (sensor.begin() == false) {
35+
Serial.println("Not connected. Please check connections and read the hookup guide.");
36+
while (1);
37+
}
38+
else {
39+
Serial.println("Connected!");
40+
}
41+
}
42+
43+
void loop() {
44+
if (sensor.isRightSwipePulled() == true) {
45+
Serial.println("Right Swipe");
46+
}
47+
48+
if (sensor.isLeftSwipePulled() == true) {
49+
Serial.println("Left Swipe");
50+
}
51+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
Library for the CAP1203
3+
By: Andrea DeVore
4+
SparkFun Electronics
5+
6+
Do you like this library? Help support SparkFun. Buy a board!
7+
8+
This sketch uses the SparkFun_CAP1203 library to initialize
9+
the capacitive touch sensor, enable the power button feature,
10+
and to detect when the power button has been pressed. This
11+
sketch also allows you to choose which pad acts as the power
12+
button and to customize how long the power button must be
13+
pressed before its triggered. Note: the pad which is set to
14+
be the power button will only act as a power button.
15+
16+
License: This code is public domain, but if you see me
17+
(or any other SparkFun employee) at the local, and you've
18+
found our code helpful, please buy us a round (Beerware
19+
license).
20+
21+
Distributed as is; no warrenty given.
22+
*/
23+
24+
#include <SparkFun_CAP1203_Registers.h>
25+
#include <SparkFun_CAP1203_Types.h>
26+
#include <Wire.h>
27+
28+
CAP1203 sensor; // Initialize sensor
29+
30+
void setup() {
31+
Wire.begin(); // Join I2C bus
32+
Serial.begin(9600); // Start serial for output
33+
34+
// Setup sensor
35+
if (sensor.begin() == false) {
36+
Serial.println("Not connected. Please check connections and read the hookup guide.");
37+
while (1);
38+
}
39+
else {
40+
Serial.println("Connected!");
41+
}
42+
43+
/* SET POWER BUTTON PAD
44+
Set which pad acts as the power button: PAD_LEFT,PAD_MIDDLE,PAD_RIGHT
45+
*/
46+
//sensor.setPowerButtonPad(PAD_LEFT);
47+
sensor.setPowerButtonPad(PAD_MIDDLE);
48+
//sensor.setPowerButtonPad(PAD_RIGHT);
49+
50+
/* GET POWER BUTTON PAD
51+
Get the current pad which acts as the power button.
52+
The function returns the pad as an interger which
53+
maps to a specific position.
54+
55+
PAD POSITION
56+
1 Left
57+
2 Middle
58+
3 Right
59+
*/
60+
int pad = sensor.getPowerButtonPad();
61+
Serial.print("Power Button Pad: ");
62+
if (pad == 1) {
63+
Serial.println("Left");
64+
}
65+
else if (pad == 2) {
66+
Serial.println("Middle");
67+
}
68+
if (pad == 3) {
69+
Serial.println("Right");
70+
}
71+
72+
/* SET POWER BUTTON TIME
73+
Set the length of time (in ms) which the designated
74+
power button must indicate a touch before being
75+
recongized as a power button touch.
76+
*/
77+
//sensor.setPowerButtonTime(PWR_TIME_280_MS); // 280 ms
78+
//sensor.setPowerButtonTime(PWR_TIME_560_MS); // 560 ms
79+
//sensor.setPowerButtonTime(PWR_TIME_1120_MS); // 1120 ms
80+
sensor.setPowerButtonTime(PWR_TIME_2240_MS); // 2240 ms
81+
82+
/* GET POWER BUTTON TIME
83+
Get the length of time the designated power button
84+
must indicate a touch before being recongized as a
85+
power button touch.
86+
*/
87+
Serial.print("Power Button Time: ");
88+
Serial.print(sensor.getPowerButtonTime());
89+
Serial.println(" ms");
90+
91+
/* SET ENABLE / DISABLE POWER BUTTON
92+
Enable or disable the power button functionality.
93+
When the power button is ENABLED, the specified pad
94+
(from setPowerButtonPad() function) acts as a power
95+
button. When the power button is DISABLED, all pads
96+
act as regular capactitive touch sensors.
97+
*/
98+
sensor.setPowerButtonEnabled(); // Enable power button
99+
//sensor.setPowerButtonDisabled(); // Disable power button
100+
101+
/* IS POWER BUTTON TOUCHED
102+
Returns the state of the power button. Returns true
103+
if ENABLED, otherwise returns false.
104+
*/
105+
Serial.print("Power Button: ");
106+
if (sensor.isPowerButtonEnabled() == true) {
107+
Serial.println("ENABLED");
108+
}
109+
else {
110+
Serial.println("DISABLED");
111+
}
112+
}
113+
114+
void loop() {
115+
if (sensor.isPowerButtonTouched() == true) {
116+
Serial.println("Power Button");
117+
while (sensor.isPowerButtonTouched() == true); // Wait until user removes finger
118+
}
119+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
Library for the CAP1203
3+
By: Andrea DeVore
4+
SparkFun Electronics
5+
6+
Do you like this library? Help support SparkFun. Buy a board!
7+
8+
This sketch uses the SparkFun_CAP1203 library to initialize
9+
the capacitive touch sensor and to stream which pad detects
10+
a touch. This sketch waits until user removes finger from the
11+
pad to detect the next touch.
12+
13+
License: This code is public domain, but if you see me
14+
(or any other SparkFun employee) at the local, and you've
15+
found our code helpful, please buy us a round (Beerware
16+
license).
17+
18+
Distributed as is; no warrenty given.
19+
*/
20+
21+
#include <SparkFun_CAP1203_Registers.h>
22+
#include <SparkFun_CAP1203_Types.h>
23+
#include <Wire.h>
24+
25+
CAP1203 sensor; // Initialize sensor
26+
27+
void setup() {
28+
Wire.begin(); // Join I2C bus
29+
Serial.begin(9600); // Start serial for output
30+
31+
// Setup sensor
32+
if (sensor.begin() == false) {
33+
Serial.println("Not connected. Please check connections and read the hookup guide.");
34+
while (1);
35+
}
36+
else {
37+
Serial.println("Connected!");
38+
}
39+
}
40+
41+
void loop() {
42+
if (sensor.isLeftTouched() == true) {
43+
Serial.println("Left");
44+
while (sensor.isLeftTouched() == true); // Wait until user removes finger
45+
}
46+
47+
if (sensor.isMiddleTouched() == true) {
48+
Serial.println("Middle");
49+
while (sensor.isMiddleTouched() == true); // Wait until user removes finger
50+
}
51+
52+
if (sensor.isRightTouched() == true) {
53+
Serial.println("Right");
54+
while (sensor.isRightTouched() == true); // Wait until user removes finger
55+
}
56+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Library for the CAP1203
3+
By: Andrea DeVore
4+
SparkFun Electronics
5+
6+
Do you like this library? Help support SparkFun. Buy a board!
7+
8+
This sketch uses the SparkFun_CAP1203 library to initialize
9+
the capacitive touch sensor and disable/enable the interrupt
10+
pins. Disabling the interrupt pin on the SparkFun CAP1203
11+
Board turns off the alert LED as well.
12+
13+
License: This code is public domain, but if you see me
14+
(or any other SparkFun employee) at the local, and you've
15+
found our code helpful, please buy us a round (Beerware
16+
license).
17+
18+
Distributed as is; no warrenty given.
19+
*/
20+
21+
#include <SparkFun_CAP1203_Registers.h>
22+
#include <SparkFun_CAP1203_Types.h>
23+
#include <Wire.h>
24+
25+
CAP1203 sensor; // Initialize sensor
26+
27+
void setup() {
28+
Wire.begin(); // Join I2C bus
29+
Serial.begin(9600); // Start serial for output
30+
31+
// Setup sensor
32+
if (sensor.begin() == false) {
33+
Serial.println("Not connected. Please check connections and read the hookup guide.");
34+
while (1);
35+
}
36+
else {
37+
Serial.println("Connected!");
38+
}
39+
40+
/* SET INTERRUPT DISABLED/ENABLED
41+
Interrupt is ENABLED as default.
42+
When the interrupt pin is DISABLED, the alert LED
43+
does not turn on. When the interrupt pin is ENABLED,
44+
the alert LED turns on when a touch is detected.
45+
*/
46+
sensor.setInterruptDisabled(); // Disable Interrupt
47+
//sensor.setInterruptEnabled(); // Enable Interrupt
48+
49+
/* IS INTERRUPT ENABLED
50+
Check the current status of the interrupt pin.
51+
Returns true if interrupt pin is enabled and
52+
false if disabled.
53+
*/
54+
Serial.print("Interrupt: ");
55+
if (sensor.isInterruptEnabled() == true){
56+
Serial.println("ENABLED");
57+
}
58+
else {
59+
Serial.println("DISABLED");
60+
}
61+
}
62+
63+
void loop() {
64+
if (sensor.isTouched() == true) {
65+
Serial.println("Touched!");
66+
while (sensor.isTouched() == true);
67+
}
68+
}

0 commit comments

Comments
 (0)