Skip to content

Commit

Permalink
Merge pull request #33 from andysheen/master
Browse files Browse the repository at this point in the history
added updating the threshold of capacitive touch on on startup
  • Loading branch information
andysheen authored Sep 24, 2020
2 parents 714b2a9 + fca586d commit 1dc2a01
Show file tree
Hide file tree
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
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions utility.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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 1dc2a01

Please sign in to comment.