Gesture sensor, soft potentiometer

I'm trying to create a gesture pad using a soft potentiometer.

Currently I have the left and right swipes being detected but I would like a single tap, and a double tap function also. I've been sitting for hours trying to get it to work however I'm a beginner with Arduino and coding so haven't got very far.

I was hoping someone would be able to help with this?

int potPin = A2;
int ledPin = 13;
int decreasing = 0;
int increasing = 1024;
int previous = 0;
int current = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  current = analogRead(potPin);
  // to check the current value use Serial.println(curr);

                      // LEFT SWIPE

// detect if the potmeter input keeps getting smaller for a certain amount of time
// (value ranges from 1024 to 0 without pullup resistor)
// if yes, then send "1" for a while before starting the detection again
  
  // checking if current value is smaller than previous. if happens mutiple 
  //times then it means a left swipe is detected.
  if(current < previous) {
    decreasing++;
  } else {
    decreasing = 0;
  }
  
  previous = current;
  
  // if a decrease has been detected 10 times, send a "1" value (and power the LED on the arduino)
  if(decreasing > 10) {
    // sends a '1' signal across the serial connection
    Serial.print(1);
  } else {
    Serial.print(0);
  }
  // delay to get rid of accidental swipes/detection
  delay(5);

                      // RIGHT SWIPE

// detect if the potmeter input keeps getting larger for a certain amount of time
// (value ranges from 1024 to 0 without pullup resistor)
// if yes, then send "2" for a while before starting the detection again

  current = analogRead(potPin);
  // to check the current value use Serial.println(curr);
  

  // checking if current value is larger than previous. if happens mutiple 
  //times then it means a right swipe is detected
  if(current > previous) {
    increasing++;
  } else {
    increasing = 0;
  }
  
  previous = current;
  
  // if an increase has been detected 10 times, send a "2" value (and power the LED on the arduino)
  if(increasing > 10) {
    //sends a '2' signal across the serial
    Serial.print(2);
  } else {
    Serial.print(0);
  }
  // delay to get rid of accidental swipes/detection
  delay(5);
}

[
![|500x500](Gesture sensor, soft potentiometer - Project Guidance - Arduino Forum
[/url])

Swipe_detection_without_led.ino (1.91 KB)

](Gesture sensor, soft potentiometer - Project Guidance - Arduino Forum)

I'm trying to create a gesture pad using a soft potentiometer.

Currently I have the left and right swipes being detected but I would like a single tap, and a double tap function also. I've been sitting for hours trying to get it to work however I'm a beginner with Arduino and coding so haven't got very far.

I was hoping someone would be able to help with this?

int potPin = A2;
int ledPin = 13;
int decreasing = 0;
int increasing = 1024;
int previous = 0;
int current = 0;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  current = analogRead(potPin);
  // to check the current value use Serial.println(curr);

                      // LEFT SWIPE

// detect if the potmeter input keeps getting smaller for a certain amount of time
// (value ranges from 1024 to 0 without pullup resistor)
// if yes, then send "1" for a while before starting the detection again
  
  // checking if current value is smaller than previous. if happens mutiple 
  //times then it means a left swipe is detected.
  if(current < previous) {
    decreasing++;
  } else {
    decreasing = 0;
  }
  
  previous = current;
  
  // if a decrease has been detected 10 times, send a "1" value (and power the LED on the arduino)
  if(decreasing > 10) {
    // sends a '1' signal across the serial connection
    Serial.print(1);
  } else {
    Serial.print(0);
  }
  // delay to get rid of accidental swipes/detection
  delay(5);

                      // RIGHT SWIPE

// detect if the potmeter input keeps getting larger for a certain amount of time
// (value ranges from 1024 to 0 without pullup resistor)
// if yes, then send "2" for a while before starting the detection again

  current = analogRead(potPin);
  // to check the current value use Serial.println(curr);
  

  // checking if current value is larger than previous. if happens mutiple 
  //times then it means a right swipe is detected
  if(current > previous) {
    increasing++;
  } else {
    increasing = 0;
  }
  
  previous = current;
  
  // if an increase has been detected 10 times, send a "2" value (and power the LED on the arduino)
  if(increasing > 10) {
    //sends a '2' signal across the serial
    Serial.print(2);
  } else {
    Serial.print(0);
  }
  // delay to get rid of accidental swipes/detection
  delay(5);

}

I've been sitting for hours trying to get it to work

So post the code that you have been trying.
Hint :- it is likely that your swipe code is interfering with your attempts to detect a single tap, so just concentrate on code that will detect that and ditch the swipe stuff for the moment.

How have you got this wired? Do you know that the wiper on an untouched sensor is floating and only becomes active once you touch it.

@DanielBrown, please do not cross-post. Threads merged.

I've done something similar with a distance sensor. Could detect swipes (move up and down, sensor was pointing up), quick pass (your tap) and hand held in place (long tap). Never did a double pass but it'll be straightforward.

Strategy: sample the sensor 5-10 times a second, store the latest 10-20 values in an array (every time moving all the values one step down, storing the latest in [0]), and every time you have a new reading analyse what happened.

Last 3-4 values all increased? Swipe up.
Last 3-4 values all decreased? Swipe down.
Last value high reading, the 2-3 values before that low reading, the 2-3 before that a much higher again? Quick pass (tap).
Double tap vs. single tap is trickier: how long to continue waiting for a second tap?

Likewise I could recognise a gesture where you make a quick down-up movement.

As you store a number of values you can check for multiple gestures. You will have to decide which to take prevalence, how long for a long/short tap, how long time to wait for a second to see a double tap or call it a single. You also have to think of how much movement and it becomes a swipe, rather than a finger held in place (people always move a bit, there's measurement noise, the readings will never be perfectly steady).