Aha ! OK The toggle-switch-function.
There are two levels:
level 1: how to apply / to use the toggle-switch-function
level 2: understand what the code inside the function is doing in detail.
level 1:
The function must be called very regularly.
Minimum is 20 times each second, to make the code responsive to a button-press that occurs at any time.
The function "gives back a result" as a boolean value "true" or "false" which could be seen as switch is "closed" / "opened"
Level 2:
The inner details require much more words to explain them.
You have asked for numbers.
A part of the code does use non-blocking timing.
The basic principle of non-blocking timiing is explained in this tutorial
But this is only a part
there are more parts
- debouncing
- state-change detection
at the moment I have just a small freetime. It will take some days until I have more time
to write a full tutorial.
best regards Stefan