Hello frieds am beginner in programming and have some exposure in electronics. Am trying to create 3 key based touch interface with MPR-121 sensor and arduino micro. each time i touch combination of (3) keys my readTouch() Function return's value form 1 to 7(1+2+4) (once after releasing my hand ). when i single tap it works as expected but when double tap it prints single tap result as well as double tap result. but what i need is only double tap result. also want to implement triple tap. i google'd and search the forum for similiar solutions but not found anything related to me...
please guide me....
//my code is :
unsigned long lastTouchTime;
unsigned int diffTouchTime;
unsigned int lastread;
unsigned int doubleTap = 0;
bool sendKey;
void loop() {
uint8_t readtouch = readTouch(); //mpr121 function returns 1 to 7 (3 touch)
diffTouchTime = millis() - lastTouchTime;
if (readtouch) {
if ( (diffTouchTime < 200) && (readtouch == lastread) ) {
doubleTap++;
}
sendKey = 1;
lastread = readtouch;
}
if ( (diffTouchTime) > 200) {
doubleTap = 1;
}
if (sendKey) { // print only once via terminal
if (doubleTap)
{
Serial.print(readtouch + 10);
} else {
Serial.print(readtouch);
}
sendKey = 0;
lastTouchTime = millis();
}
}