Skip to content

Commit bcdea7a

Browse files
author
Nathan Seidle
committed
Change header name. Change examples to only call necessary header.
1 parent ef1c419 commit bcdea7a

File tree

8 files changed

+151
-98
lines changed

8 files changed

+151
-98
lines changed

examples/Example01_BasicReading/Example01_BasicReading.ino

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,43 @@
1717
Distributed as is; no warrenty given.
1818
*/
1919

20-
#include <SparkFun_CAP1203_Registers.h>
21-
#include <SparkFun_CAP1203_Types.h>
2220
#include <Wire.h>
21+
#include "SparkFun_CAP1203.h" // Click here to get the library: http://librarymanager/All#SparkFun_CAP1203
2322

24-
CAP1203 sensor; // Initialize sensor
23+
CAP1203 sensor; // Initialize sensor
2524

26-
void setup() {
27-
Wire.begin(); // Join I2C bus
28-
Serial.begin(9600); // Start serial for output
25+
void setup()
26+
{
27+
Wire.begin(); // Join I2C bus
28+
Serial.begin(9600); // Start serial for output
2929

3030
// Setup sensor
31-
if (sensor.begin() == false) {
31+
if (sensor.begin() == false)
32+
{
3233
Serial.println("Not connected. Please check connections and read the hookup guide.");
33-
while (1);
34+
while (1)
35+
;
3436
}
35-
else {
37+
else
38+
{
3639
Serial.println("Connected!");
3740
}
3841
}
3942

40-
void loop() {
41-
if (sensor.isLeftTouched() == true) {
43+
void loop()
44+
{
45+
if (sensor.isLeftTouched() == true)
46+
{
4247
Serial.println("Left");
4348
}
4449

45-
if (sensor.isMiddleTouched() == true) {
50+
if (sensor.isMiddleTouched() == true)
51+
{
4652
Serial.println("Middle");
4753
}
4854

49-
if (sensor.isRightTouched() == true) {
55+
if (sensor.isRightTouched() == true)
56+
{
5057
Serial.println("Right");
5158
}
5259
}

examples/Example02_DetectAnyTouch/Example02_DetectAnyTouch.ino

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,33 @@
1717
Distributed as is; no warrenty given.
1818
*/
1919

20-
#include <SparkFun_CAP1203_Registers.h>
21-
#include <SparkFun_CAP1203_Types.h>
2220
#include <Wire.h>
21+
#include "SparkFun_CAP1203.h" // Click here to get the library: http://librarymanager/All#SparkFun_CAP1203
2322

24-
CAP1203 sensor; // Initialize sensor
23+
CAP1203 sensor; // Initialize sensor
2524

26-
void setup() {
27-
Wire.begin(); // Join I2C bus
28-
Serial.begin(9600); // Start serial for output
25+
void setup()
26+
{
27+
Wire.begin(); // Join I2C bus
28+
Serial.begin(9600); // Start serial for output
2929

3030
// Setup sensor
31-
if (sensor.begin() == false) {
31+
if (sensor.begin() == false)
32+
{
3233
Serial.println("Not connected. Please check connections and read the hookup guide.");
33-
while (1);
34+
while (1)
35+
;
3436
}
35-
else {
37+
else
38+
{
3639
Serial.println("Connected!");
3740
}
3841
}
3942

40-
void loop() {
41-
if (sensor.isTouched() == true) {
43+
void loop()
44+
{
45+
if (sensor.isTouched() == true)
46+
{
4247
Serial.println("Touch");
4348
}
4449
}

examples/Example03_DetectSwipe/Example03_DetectSwipe.ino

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,38 @@
2020
Distributed as is; no warrenty given.
2121
*/
2222

23-
#include <SparkFun_CAP1203_Registers.h>
24-
#include <SparkFun_CAP1203_Types.h>
2523
#include <Wire.h>
24+
#include "SparkFun_CAP1203.h" // Click here to get the library: http://librarymanager/All#SparkFun_CAP1203
2625

27-
CAP1203 sensor; // Initialize sensor
26+
CAP1203 sensor; // Initialize sensor
2827

29-
void setup() {
30-
Wire.begin(); // Join I2C bus
31-
Serial.begin(9600); // Start serial for output
28+
void setup()
29+
{
30+
Wire.begin(); // Join I2C bus
31+
Serial.begin(9600); // Start serial for output
3232

3333
// Setup sensor
34-
if (sensor.begin() == false) {
34+
if (sensor.begin() == false)
35+
{
3536
Serial.println("Not connected. Please check connections and read the hookup guide.");
36-
while (1);
37+
while (1)
38+
;
3739
}
38-
else {
40+
else
41+
{
3942
Serial.println("Connected!");
4043
}
4144
}
4245

43-
void loop() {
44-
if (sensor.isRightSwipePulled() == true) {
46+
void loop()
47+
{
48+
if (sensor.isRightSwipePulled() == true)
49+
{
4550
Serial.println("Right Swipe");
4651
}
4752

48-
if (sensor.isLeftSwipePulled() == true) {
53+
if (sensor.isLeftSwipePulled() == true)
54+
{
4955
Serial.println("Left Swipe");
5056
}
5157
}

examples/Example04_PowerButton/Example04_PowerButton.ino

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,25 @@
2121
Distributed as is; no warrenty given.
2222
*/
2323

24-
#include <SparkFun_CAP1203_Registers.h>
25-
#include <SparkFun_CAP1203_Types.h>
2624
#include <Wire.h>
25+
#include "SparkFun_CAP1203.h" // Click here to get the library: http://librarymanager/All#SparkFun_CAP1203
2726

28-
CAP1203 sensor; // Initialize sensor
27+
CAP1203 sensor; // Initialize sensor
2928

30-
void setup() {
31-
Wire.begin(); // Join I2C bus
32-
Serial.begin(9600); // Start serial for output
29+
void setup()
30+
{
31+
Wire.begin(); // Join I2C bus
32+
Serial.begin(9600); // Start serial for output
3333

3434
// Setup sensor
35-
if (sensor.begin() == false) {
35+
if (sensor.begin() == false)
36+
{
3637
Serial.println("Not connected. Please check connections and read the hookup guide.");
37-
while (1);
38+
while (1)
39+
;
3840
}
39-
else {
41+
else
42+
{
4043
Serial.println("Connected!");
4144
}
4245

@@ -59,13 +62,16 @@ void setup() {
5962
*/
6063
int pad = sensor.getPowerButtonPad();
6164
Serial.print("Power Button Pad: ");
62-
if (pad == 1) {
65+
if (pad == 1)
66+
{
6367
Serial.println("Left");
6468
}
65-
else if (pad == 2) {
69+
else if (pad == 2)
70+
{
6671
Serial.println("Middle");
6772
}
68-
if (pad == 3) {
73+
if (pad == 3)
74+
{
6975
Serial.println("Right");
7076
}
7177

@@ -77,7 +83,7 @@ void setup() {
7783
//sensor.setPowerButtonTime(PWR_TIME_280_MS); // 280 ms
7884
//sensor.setPowerButtonTime(PWR_TIME_560_MS); // 560 ms
7985
//sensor.setPowerButtonTime(PWR_TIME_1120_MS); // 1120 ms
80-
sensor.setPowerButtonTime(PWR_TIME_2240_MS); // 2240 ms
86+
sensor.setPowerButtonTime(PWR_TIME_2240_MS); // 2240 ms
8187

8288
/* GET POWER BUTTON TIME
8389
Get the length of time the designated power button
@@ -95,25 +101,30 @@ void setup() {
95101
button. When the power button is DISABLED, all pads
96102
act as regular capactitive touch sensors.
97103
*/
98-
sensor.setPowerButtonEnabled(); // Enable power button
104+
sensor.setPowerButtonEnabled(); // Enable power button
99105
//sensor.setPowerButtonDisabled(); // Disable power button
100106

101107
/* IS POWER BUTTON TOUCHED
102108
Returns the state of the power button. Returns true
103109
if ENABLED, otherwise returns false.
104110
*/
105111
Serial.print("Power Button: ");
106-
if (sensor.isPowerButtonEnabled() == true) {
112+
if (sensor.isPowerButtonEnabled() == true)
113+
{
107114
Serial.println("ENABLED");
108115
}
109-
else {
116+
else
117+
{
110118
Serial.println("DISABLED");
111119
}
112120
}
113121

114-
void loop() {
115-
if (sensor.isPowerButtonTouched() == true) {
122+
void loop()
123+
{
124+
if (sensor.isPowerButtonTouched() == true)
125+
{
116126
Serial.println("Power Button");
117-
while (sensor.isPowerButtonTouched() == true); // Wait until user removes finger
127+
while (sensor.isPowerButtonTouched() == true)
128+
; // Wait until user removes finger
118129
}
119130
}

examples/Example05_DetectCurrentTouch/Example05_DetectCurrentTouch.ino

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,49 @@
1818
Distributed as is; no warrenty given.
1919
*/
2020

21-
#include <SparkFun_CAP1203_Registers.h>
22-
#include <SparkFun_CAP1203_Types.h>
2321
#include <Wire.h>
22+
#include "SparkFun_CAP1203.h" // Click here to get the library: http://librarymanager/All#SparkFun_CAP1203
2423

25-
CAP1203 sensor; // Initialize sensor
24+
CAP1203 sensor; // Initialize sensor
2625

27-
void setup() {
28-
Wire.begin(); // Join I2C bus
29-
Serial.begin(9600); // Start serial for output
26+
void setup()
27+
{
28+
Wire.begin(); // Join I2C bus
29+
Serial.begin(9600); // Start serial for output
3030

3131
// Setup sensor
32-
if (sensor.begin() == false) {
32+
if (sensor.begin() == false)
33+
{
3334
Serial.println("Not connected. Please check connections and read the hookup guide.");
34-
while (1);
35+
while (1)
36+
;
3537
}
36-
else {
38+
else
39+
{
3740
Serial.println("Connected!");
3841
}
3942
}
4043

41-
void loop() {
42-
if (sensor.isLeftTouched() == true) {
44+
void loop()
45+
{
46+
if (sensor.isLeftTouched() == true)
47+
{
4348
Serial.println("Left");
44-
while (sensor.isLeftTouched() == true); // Wait until user removes finger
49+
while (sensor.isLeftTouched() == true)
50+
; // Wait until user removes finger
4551
}
4652

47-
if (sensor.isMiddleTouched() == true) {
53+
if (sensor.isMiddleTouched() == true)
54+
{
4855
Serial.println("Middle");
49-
while (sensor.isMiddleTouched() == true); // Wait until user removes finger
56+
while (sensor.isMiddleTouched() == true)
57+
; // Wait until user removes finger
5058
}
5159

52-
if (sensor.isRightTouched() == true) {
60+
if (sensor.isRightTouched() == true)
61+
{
5362
Serial.println("Right");
54-
while (sensor.isRightTouched() == true); // Wait until user removes finger
63+
while (sensor.isRightTouched() == true)
64+
; // Wait until user removes finger
5565
}
5666
}

examples/Example06_DisableInterrupt/Example06_DisableInterrupt.ino

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,25 @@
1818
Distributed as is; no warrenty given.
1919
*/
2020

21-
#include <SparkFun_CAP1203_Registers.h>
22-
#include <SparkFun_CAP1203_Types.h>
2321
#include <Wire.h>
22+
#include "SparkFun_CAP1203.h" // Click here to get the library: http://librarymanager/All#SparkFun_CAP1203
2423

25-
CAP1203 sensor; // Initialize sensor
24+
CAP1203 sensor; // Initialize sensor
2625

27-
void setup() {
28-
Wire.begin(); // Join I2C bus
29-
Serial.begin(9600); // Start serial for output
26+
void setup()
27+
{
28+
Wire.begin(); // Join I2C bus
29+
Serial.begin(9600); // Start serial for output
3030

3131
// Setup sensor
32-
if (sensor.begin() == false) {
32+
if (sensor.begin() == false)
33+
{
3334
Serial.println("Not connected. Please check connections and read the hookup guide.");
34-
while (1);
35+
while (1)
36+
;
3537
}
36-
else {
38+
else
39+
{
3740
Serial.println("Connected!");
3841
}
3942

@@ -43,7 +46,7 @@ void setup() {
4346
does not turn on. When the interrupt pin is ENABLED,
4447
the alert LED turns on when a touch is detected.
4548
*/
46-
sensor.setInterruptDisabled(); // Disable Interrupt
49+
sensor.setInterruptDisabled(); // Disable Interrupt
4750
//sensor.setInterruptEnabled(); // Enable Interrupt
4851

4952
/* IS INTERRUPT ENABLED
@@ -52,17 +55,22 @@ void setup() {
5255
false if disabled.
5356
*/
5457
Serial.print("Interrupt: ");
55-
if (sensor.isInterruptEnabled() == true){
58+
if (sensor.isInterruptEnabled() == true)
59+
{
5660
Serial.println("ENABLED");
5761
}
58-
else {
62+
else
63+
{
5964
Serial.println("DISABLED");
6065
}
6166
}
6267

63-
void loop() {
64-
if (sensor.isTouched() == true) {
68+
void loop()
69+
{
70+
if (sensor.isTouched() == true)
71+
{
6572
Serial.println("Touched!");
66-
while (sensor.isTouched() == true);
73+
while (sensor.isTouched() == true)
74+
;
6775
}
6876
}

0 commit comments

Comments
 (0)