1

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.

Michel Keijzers
  • 13,014
  • 7
  • 41
  • 58
MrWave
  • 13
  • 2

1 Answers1

0

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.

Michel Keijzers
  • 13,014
  • 7
  • 41
  • 58