#define BUTTON_PIN 21         // GPIO21 pin connected to button
#define LONG_PRESS_TIME 1000  // 1000 milliseconds

// Variables will change
int lastState = LOW;  // the previous state from the input pin
int currentState;     // the current reading from the input pin

unsigned long pressedTime = 0;
unsigned long releasedTime = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(BUTTON_PIN, INPUT_PULLUP);
}

void loop() {
  // put your main code here, to run repeatedly:
  // read the state of the switch/button
  currentState = digitalRead(BUTTON_PIN);

  if (lastState == HIGH && currentState == LOW)   // button is pressed
    pressedTime = millis();
  else if (lastState == LOW && currentState == HIGH)   // button is released
    releasedTime = millis();

  long pressDuration = releasedTime - pressedTime;

  if (pressDuration > LONG_PRESS_TIME)
    Serial.println("A long press is detected");
  
  lastState = currentState; // save the last state
}