Skip to content

Commit

Permalink
added updating the threshold of capacitive touch on on startup
Browse files Browse the repository at this point in the history
andysheen committed Sep 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 69fd38e commit fca586d
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ESP32-SOCKETIO.ino
Original file line number Diff line number Diff line change
@@ -129,15 +129,19 @@ class CapacitiveConfig: public ButtonConfig {
_pin = pin;
_threshold = threshold;
}

void setThreshold(uint16_t CapThreshold) {
_threshold = CapThreshold;
}
protected:
int readButton(uint8_t /*pin*/) override {
uint16_t val = touchRead(_pin);
return (val < _threshold) ? LOW : HIGH;
}

};

#define TOUCH_THRESHOLD 60
int TOUCH_THRESHOLD = 60;
int TOUCH_HYSTERESIS = 20;
#define LONG_TOUCH 1500
CapacitiveConfig touchConfig(CAPTOUCH, TOUCH_THRESHOLD);
AceButton buttonTouch(&touchConfig);
@@ -167,9 +171,11 @@ int port = 80; // Socket.IO Port Address
char path[] = "/socket.io/?transport=websocket"; // Socket.IO Base Path

void setup() {

setupPixels();
Serial.begin(115200);
setupPins();
setupCapacitiveTouch();

//create 10 digit ID
myID = generateID();
13 changes: 13 additions & 0 deletions utility.ino
Original file line number Diff line number Diff line change
@@ -167,3 +167,16 @@ String generateID() {
String out = String(low);
return out;
}

void setupCapacitiveTouch() {
int touchAverage = 0;
for (byte i = 0; i < 10; i++) {
touchAverage = touchAverage+touchRead(CAPTOUCH);
delay(100);
}
touchAverage = touchAverage/10;
TOUCH_THRESHOLD = touchAverage - TOUCH_HYSTERESIS;
Serial.print("Touch threshold is:");
Serial.println(TOUCH_THRESHOLD);
touchConfig.setThreshold(TOUCH_THRESHOLD);
}

0 comments on commit fca586d

Please sign in to comment.