Last active
September 25, 2017 21:14
-
-
Save jbobrow/107271fdeb899f8c5aa4b91918194449 to your computer and use it in GitHub Desktop.
A Processing sketch to demonstrate multiple click detection as desired for the Blinks platform.
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
/* | |
* A quick multiple click test sample application | |
* | |
* by Jonathan Bobrow | |
* 09.25.2017 | |
*/ | |
int clickTime = 330; | |
int millisWhenPressed = 0; | |
int numberOfClicks = 0; | |
boolean startedClickSequence = false; | |
void setup() { | |
} | |
void draw() { | |
if(millis() - millisWhenPressed > clickTime) { | |
// our window expired | |
if(startedClickSequence) { | |
// we started a click sequence, so lets handle its results now | |
println("number of clicks: " + numberOfClicks); | |
// reset the number of clicks | |
numberOfClicks = 0; | |
// no longer in a click sequence | |
startedClickSequence = false; | |
} | |
} | |
} | |
void mousePressed() { | |
// start window of click time | |
millisWhenPressed = millis(); | |
// confirm that we are in a click sequence or starting one | |
startedClickSequence = true; | |
} | |
void mouseReleased() { | |
if(millis() - millisWhenPressed < clickTime) { | |
// released within click window | |
// count up our clicks | |
numberOfClicks++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment