Nibbles and Bits
The Care and Feeding of My Pet Arduino by Budd Churchward - WB7FHC - NIBBLES AND BITS LIBRARY
«1 2 3 4 5 6 7 8 9 10 11 12 13 15 16 17 18 19 » |
Section 4
We are going to introduce a Boolean variable to the sketch. We will use it
to keep track if we have gone to a new line. Our goal is to do that only once
after the key has been released. We will also add a very short delay to the
part where the key is down, which will reduce the number of X's that are printed.
We are declaring it at the start of the sketch so that we can adjust it here
but use it later to weed out fake clicks and key bounce.
Copy the highlighted sections on the right and and paste them into your sketch in the places shown.
The line highlighted in orange should be deleted.
Serial.println();is now in the new If structure that you are pasting in during this step. Compile and Run the sketch. Notice the new line in the sketch that says:
if (!characterDone) {
characterDone is our Boolean variable. The ! means NOT which means the code
in our curly brackets will only execute when characterDone is FALSE. As soon as we have
printed a new line, we switch its value to TRUE so it only prints one 'line feed'. When you
press your keydown again, we switch the value back to FALSE so it will go to a new line
when you release the key.
|
|