Please help me understand this code

UPDATE: I made a hardware square wave generator arbitrarily outputting 26 pulses visible on my scope during the interval pulse. Using JohnLIncoln's suggestion to comment out the offending line, it does work, somewhat. It counts 26 pulses, sometimes 25 and occasionally 24. That may be due to glitches in the hardware, as it's not the same as a commercial signal generator.

What I don't like is that it outputs the number of pulses as they are counted. I need only a single total of all the pulses within the interval. I've forgotten so much about coding that I'm at a standstill. As others have mentioned, I may be expecting too much from Arduino and may be better off using an up-counter IC and using the Arduino to display its output.

Horace, your ESP code comes closer to what I'm looking for, showing the total number of pulses within the interval. I've never heard of ESP32 and have spent some time looking it up. Can you use the Arduino IDE to program it? If so, how does it show up in the devices?