Using the library is pretty straightforward. The first thing
that you will notice is this
line:
This is necessary to tell the compiler to use the Bounce library.
You then have the following line:
Do not worry about the syntax of this line at the moment; it is actually C++ rather than C
syntax, and you will not be meeting C++ until
Chapter 11
. For now, you will just have to
be content
to know that this sets up a
bouncer
object
for the pin specified, with a
debounce period of 5 milliseconds.
From now on, you use that
bouncer
object to find out what the key is doing rather than
reading the digital input directly. It has put a kind of debouncing wrapper around your
input pin. So, deciding whether a button has been pressed is wrapped up in this line:
The function
update
returns true if something has changed with the
bouncer
object and
the second part of the condition checks whether the button went
Dostları ilə paylaş: