Skip to content

Instantly share code, notes, and snippets.

@jbobrow
Created March 1, 2019 21:30
Show Gist options
  • Save jbobrow/3d57f3efceb8709949474a4024a286e6 to your computer and use it in GitHub Desktop.
Save jbobrow/3d57f3efceb8709949474a4024a286e6 to your computer and use it in GitHub Desktop.
Test the long press validation with action on release
/*
* Button Long Press and confirm on release
*/
bool hasBeenLongPressed = false;
bool bFastPulse = false;
byte bri[6];
void setup() {
// put your setup code here, to run once:
}
void loop() {
displayPulse();
// put your main code here, to run repeatedly:
if (buttonLongPressed()) {
hasBeenLongPressed = true;
}
if (buttonDown()) {
if(hasBeenLongPressed) {
// show that long press is registered
// setColor(GREEN);
// rotate white around
setColor(OFF);
FOREACH_FACE(f){
if((millis()/60) % 6 == f) {
bri[f] = 255;
}
if( bri[f] >= 15 ) {
bri[f] -= 15;
}
setColorOnFace(dim(WHITE, bri[f]), f);
}
}
}
if (buttonReleased()) {
if(hasBeenLongPressed) {
// commit to the long press action
bFastPulse = !bFastPulse;
}
hasBeenLongPressed = false;
}
}
void displayPulse() {
if(bFastPulse) {
setColor(dim(WHITE, 127 + 127*sin(millis()/90.f)));
}
else {
setColor(dim(WHITE, 127 + 127*sin(millis()/360.f)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment