Skip to content

Commit 3c1fdc6

Browse files
authored
Merge pull request #19 from arduino-libraries/touch-sensitivity-individually
Touch sensitivity individually
2 parents 3f744d5 + 251c5dd commit 3c1fdc6

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ MKRIoTCarrier carrier;
55
// When CARRIER_CASE is true it's set to 4 (further)
66
// But if you use Buttons.updateConfig(value) It will not set the above values
77

8-
unsigned int threshold = 100;
8+
unsigned int threshold = 98;
9+
unsigned int threshold_btn_0 = 95;
910

1011
void setup() {
1112
// put your setup code here, to run once:
@@ -14,15 +15,35 @@ void setup() {
1415

1516
//CARRIER_CASE = false;
1617
//Now we can set our custom touch threshold
18+
// First we update all the buttons with the new threshold
19+
// Then we overwrite individually one of them (they can be all set individually too)
1720
carrier.Buttons.updateConfig(threshold);
21+
carrier.Button0.updateConfig(threshold_btn_0);
1822
carrier.begin();
1923
}
2024

2125
void loop() {
2226
// put your main code here, to run repeatedly:
2327
carrier.Buttons.update();
24-
//Lets test 1 button, they should all react in the same way
28+
29+
// Verify your thresholds
2530
if (carrier.Button0.getTouch()) {
26-
Serial.println("touching");
31+
Serial.println("touching 0");
32+
}
33+
34+
if (carrier.Button1.getTouch()) {
35+
Serial.println("touching 1");
36+
}
37+
38+
if (carrier.Button2.getTouch()) {
39+
Serial.println("touching 2");
40+
}
41+
42+
if (carrier.Button3.getTouch()) {
43+
Serial.println("touching 3");
44+
}
45+
46+
if (carrier.Button4.getTouch()) {
47+
Serial.println("touching 4");
2748
}
2849
}

src/Arduino_MKRIoTCarrier.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ int MKRIoTCarrier::begin(){
4444

4545
if(!Buttons.customSens){
4646

47-
if(CARRIER_CASE){
48-
TOUCH.setSensorsSensitivity(4u);
49-
}else{
50-
TOUCH.setSensorsSensitivity(100u);
51-
}
52-
Buttons.begin(); //init buttons
47+
if(CARRIER_CASE){
48+
TOUCH.setSensorsSensitivity(5u);
49+
}else{
50+
TOUCH.setSensorsSensitivity(100u);
51+
}
5352
}
53+
Buttons.begin(); //init buttons
5454

5555
//init LEDs
5656
leds.begin();

src/Arduino_MKRIoTCarrier_Qtouch.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ MKRIoTCarrier_Qtouch::MKRIoTCarrier_Qtouch(int padIndex, MKRIoTCarrier_Qtouch_Ma
3030
bool MKRIoTCarrier_Qtouch::getTouch(){
3131
bool getState = _pManager->t_state[_padIndex];
3232
_saveToHistory(getState);
33+
3334
return(getState);
3435
}
3536

@@ -82,9 +83,17 @@ bool MKRIoTCarrier_Qtouch::onTouchChange(){
8283
}
8384
}
8485

86+
87+
void MKRIoTCarrier_Qtouch::updateConfig(int newSens){
88+
TOUCH.setSensorsSensitivity(newSens, _padIndex);
89+
//TOUCH.begin();
90+
_pManager->customSens = true;
91+
}
92+
93+
8594
//Manager
8695
bool MKRIoTCarrier_Qtouch_Manager::begin(){
87-
return TOUCH.begin();
96+
return TOUCH.begin();
8897
}
8998
MKRIoTCarrier_Qtouch_Manager::MKRIoTCarrier_Qtouch_Manager(){
9099

@@ -103,6 +112,6 @@ void MKRIoTCarrier_Qtouch_Manager::update(){
103112
void MKRIoTCarrier_Qtouch_Manager::updateConfig(int newSens){
104113
TOUCH.setSensorsSensitivity(newSens);
105114
//TOUCH.setSernsorsHysteresis(newHyst);
106-
TOUCH.begin();
107-
customSens = true;
115+
//TOUCH.begin();
116+
customSens = true;
108117
}

src/Arduino_MKRIoTCarrier_Qtouch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class MKRIoTCarrier_Qtouch{
4949
bool onTouchUp();
5050
bool onTouchChange();
5151

52+
void updateConfig(int newSens);
53+
5254
private:
5355
MKRIoTCarrier_Qtouch_Manager * _pManager;
5456
int _padIndex;

0 commit comments

Comments
 (0)