i would suggest you don't use the delay() function on your program.
The delay() function is a blocking function, which meant that whenever you are using it NOTHING else can happen. For instance you can read any inputs.
A solution would be to use the idea from the BlinkWithoutDelay sketch. You can find it on your IDE or here:
It is a simple idea. save the time ( millis() ) of an event into a variable. this way you can always compare it with the current time and see how much time has passed. If, for instance, a second as passed, then do something...
Take a look to the link above, i think you will understand it better...
![]()