that code in the example checks (and calls the callback if a change is detected) as fast as possible and uses a delay only if one change was detected to avoid bouncing on all the triggered rockers
Yes, sorry. Read not too close enough.
But it still stalls processing using delay().
a7
agree with that. It's not a need, it's a lazy and cheap way to deal with it and it works because most of the time those switches are operated by humans and so you won't notice the 15ms lag if you are unlucky and get caught in the delay
also if 2 rockers are flipped at the same time, you have 2 call backs and so the detection of the seconds happens after the first callback (at least the way I wrote the code) so you can have a lag there too
It ultimately depends on what the button the human is pushing is for.
Calling an elevator - 100 milliseconds, maybe even require that the caller stay on a button for N ms to be sure s/he really wants an elevator car to come.
Getting off a kill shot in Vixens Laser of Doom, 20 ms is⌠unacceptable!
I don't use call backs of my own much, so I missed that. If the callbacks do something, I'm all for it. If they make a mark somewhere to be picked up later, that delay() gets in the way.
And lazy? No programmer is truly lazy. We often spend hours to do something by computer that the guy at the next workstation did by hand in 10 minutes. We win when the need to do the exact same thing 42 or 42 million times cropsâŚ
a7
Ah! I understand the difference now! Once the re-check is done, it should see the correct state without the need for a regular delay. Thank you for that excellent breakdown @alto777 !
I consider this question solved and the discussion very enjoyable. I will update Projects when I move forward.
Well you have only one core so when youâll be busy doing something you wonât be polling the buttons⌠use of callbacks or not
Not true. If I can give attention to processes expressed as state machines, I can be doing the proverbial two things at once⌠or seven, all before breakfast.
a7
Sure, up to the granularity of the longest step of your state machine is what I meant.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.