Easy Double-Tap
This function can be used to detect a double-tap on any button. It's as simple as that!
|
RATE
|
- Code: Select all
//Maximum gap between tap to register double tap
int Double_Tap_Gap = 150;
//Don't change these
int Button_State = 0;
int Button_Timing;
main {
// Use the function like this:
//
// if (DoubleTap(BUTTON GOES HERE) == TRUE) {
// STUFF TO DO GOES HERE
// }
}
function DoubleTap(Button) {
// Detect Double-Tap
if(Button_State == 0) {
if(get_val(Button)) Button_State = 1;
} else if(Button_State == 1) {
if(!get_val(Button)) { Button_Timing = 0; Button_State = 2; }
} else if(Button_State == 2) {
if(get_val(Button)) { Button_State = 1; return TRUE; }
Button_Timing = Button_Timing + get_rtime();
if(Button_Timing > Double_Tap_Gap) Button_State = 0;
}
}