how to implement double tap and triple tap with MPR121

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();
}
}

That doesn't look like the entire code. It doesn't compile.
Also please use code tags, the upper left symbol in the Quick Reply window.

#include <Adafruit_MPR121.h>
#include <Wire.h>

Adafruit_MPR121 cap = Adafruit_MPR121();

unsigned long lastTouchTime;
unsigned int diffTouchTime;
unsigned int lastread;
bool doubleTap = 0;
bool sendKey;

void setup() {
 Serial.begin(9600);
 cap.begin();
}


void loop() {
 uint8_t readtouch = cap.touched();      //give int value according to the touch am using one 0,1,and 2 pads.
 diffTouchTime = millis() - lastTouchTime;
 if (readtouch) {
   if ( (diffTouchTime < 200) && (readtouch == lastread) ) {     //double tap timing and tap same key
     doubleTap=doubleTap+1;
   }
   sendKey = 1;                              // print once variable // 
   lastread = readtouch;
 }

 if ( (diffTouchTime) > 200) {
   doubleTap = 0;
 }
 if (sendKey) {                     // print only once via terminal

   if (doubleTap)
   {
     Serial.print(readtouch + 10);    
   } else {
     Serial.print(readtouch);
   }

   sendKey = 0;
   lastTouchTime = millis();
 }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.