hold button

good day. does anyone here can share a simple code that can detect a long hold from a button? thanks in advance :)

Why don't you try something. You need to keep track of the previous switch state. Read the current switch state (currState) at the start of loop, and copy the value to the previous state (prevState) at the end of loop.

Something like this:

int currState;
int prevState = LOW;

int somePin = 4; // Put your value here

void loop()
{
   currState = digitalRead(somePin);

   // Do some stuff

  prevState = currState;
}

Then you need to detect transitions, from released to pressed and from pressed to released. How do you know when a transition has occured? That's easy. The values in currState and prevState will be different.

if(currState != prevState)
{
  // A transition occurred
}

When the transition is from released to pressed, record the pressed time. When the transition is from pressed to released, record the released time.

unsigned long pressedTime;
unsigned long releasedTime;

This goes in the if block:

if(currState == ????) // Replace ???? with HIGH or LOW, whichever means pressed for you
  pressedTime = millis();
else
{
  releasedTime = millis();
  // Compute the time the switch was pressed
}

The time that the switch was pressed is releasedTime - pressedTime. Once you know how long the switch was pressed, you can make decisions based on that time.