For my hardware, I need to check if the button was pressed, but I need to do things only once every half a second.

if (digitalRead(pin) == HIGH) { doStuff(); delay(500); }

The above does not work, because I have to check other things in the main loop as well.


You should use the millis function (see millis).

Create a variable of type unsigned long and check it against the current time, with some offset.

See also the debouncing example, how to use this function and maybe you want to implement the debouncing too.
