Is it really a button type switch or some other kind of sensor?
I ask because a mechanical switch may not be the best at high speeds.
And the way you have the code implies the button is pulled high and at button press goes to zero volts. This can cause arcing as the contacts open giving the chance of several "make/breaks" on each press.
If the switch were wired pulled low and pressing it brought it high then the arcing is almost not a problem.
Just thoughts....
Bookmarks