 #define VERIFY 4
 #define CONNECTED 5
 #define SOFTPOT_THREASHOLD 950
+#define SOFTPOT_DELTA_THREASHOLD 111
 #define DELAY_IN_WAIT 1000000
 unsigned long session_id = 0xA90;
 

  case CONFIRM:
    // send out the signal to THE selected XBee
    // WAIT for the confirmation message to arrive
    
    state = CONNECTED;
    break;
  case VERIFY:
    // when there are multiple targets who have responded
    // one of the LED should be on at this case
    Serial.println("[VERIFY] Detecting gestures");

    softpotReading = analogRead(softpotPin);
    
    // digitalWrite(ledPin, HIGH);
    // then based on the gesture, we start to rotate them 
    state = CONNECTED;
    break;
  case CONNECTED:


  digitalWrite(ledPin, LOW);
  XBee.begin(9600);
  XBeePacketCounter = 0;
  pressed = false;
  released = false;
  last_release_time = 0;
}

// void test slider detection
void loop3() {
  delay(10);
  int delta_threshold = SOFTPOT_DELTA_THREASHOLD;
  if (XBeePacketCounter > 5) {
    // this happens really rare
    // you will only have 800 of the whole slider to use
    // then each step is 800/XBeePacketCounter
    delta_threshold = 800/XBeePacketCounter;
  }
    
  softpotReading = analogRead(softpotPin);
  
  Serial.print("Softpot Reading: ");
  Serial.println(softpotReading);

  if (softpotReading < SOFTPOT_THREASHOLD){
    // tapped on
    pressed = true;    
  }
  
  // should detect double click here:
  if (pressed == true && softpotReading > SOFTPOT_THREASHOLD) {
    // hand left, expected to have double tap
    // bug is the release time is updated every time here
    last_release_time = millis();
    Serial.println("pressed");
    released = true;
    pressed = false;
  }
  if (released == true && softpotReading < SOFTPOT_THREASHOLD) {
    // detect if tapped again in a timely fashion
    unsigned long new_press_time = millis();
    if (new_press_time - last_release_time < 300) {
      // definitely timeout
      Serial.println("tap event detected");
      delay(4000);
      released = false;
      pressed = false;
    }
    
  }
}

void loop() {
