Created
October 19, 2018 23:24
-
-
Save wybiral/7a1c0dfcdc5a70624c64056132f9c978 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Touch pin cutoff value | |
#define CUTOFF 20 | |
// Amount of time held before touch fires event (ms) | |
#define DURATION 100 | |
// Touch state (0=none, 1=touched+waiting, 2=touched+sent) | |
int state; | |
int start; | |
void setup() { | |
Serial.begin(115200); | |
state = 0; | |
} | |
void loop() { | |
const int t = millis(); | |
const int value = touchRead(T0); | |
const bool touched = (value < CUTOFF); | |
if (state > 0) { | |
if (state == 1 && t - start > DURATION) { | |
state = 2; | |
Serial.println("touch"); | |
} else if (!touched) { | |
state = 0; | |
} | |
} else { | |
if (touched) { | |
state = 1; | |
start = t; | |
} | |
} | |
delay(25); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment