Gauging button bounce on an #esp32 using atlast forth

I thought I’d try to get some kind of handle as to how much a button is bouncing around. Here’s the code:

23 input_pullup pinm
variable count
: ++ dup @ 1+ swap ! ;
: 0count 0 count ! ;
: igo 23 digr v0 @ <> if count ++   1 v0 @ - v0 ! then ;
: go 0count begin  igo     key? until count @ . ;

It counts the number of times the value of the button on pin 23 changes. Enter “go” on the serial port, press the button down, then release. Then hit the Return key to stop the loop and obtain a count of the number of times a change had been detected.

Most of the time it prints the value 2, which is the expected answer. Occasionally it will print 4 or 8. The highest value it reached was 10. So although my switch is pretty good, debouncing is still necessary.


About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s