The next argument is the name of the function that is to
be called when there is an
interrupt, and the final argument is a constant that will be one of
CHANGE, RISING
, or
FALLING
.
Figure 7-4
summarizes these options.
If
the interrupt mode is CHANGE, then either a RISING from 0 to 1
or a FALLING
from 1 to 0 will both trigger an interrupt.
You can disable interrupts
using the function
noInterrupts
.
This stops all interrupts
from both interrupt channels. You can resume using interrupts
again by calling the
function
interrupts
.
Conclusion
In this chapter, you have looked at some of the handy features that the Arduino standard
library provides. These features will save
you some programming effort, and if there is
one thing that a good programmer likes, it is being able to use high-quality work done by
other people.
In the next chapter, we will extend what we learned about data structures in
Chapter 5
and look at how you go about remembering data on the Arduino after the power goes off.
8
Data Storage
When you
give values to variables, the Arduino board will remember those values only as
long as the power is on. The moment that you turn the power off or reset the board, all that
data is lost.
In this chapter, we look at some ways to hang on to that data.
Constants
If the data that you want to store does not change, then you can just set the data up each
time that the Arduino starts. An example of this approach is the case in the letters array in
your Morse code translator of
Chapter 5
(sketch 5-05).
You used the following code to define a variable of the correct size and fill it with the
data that you needed:
You may remember that you did the calculation and decided that you had plenty of your
meager 2K to spare. However, if memory was a bit tight, it would be far better to be able
to store this data in the 32K of flash memory used to store programs, rather than the 2K of
RAM. There is a means of doing this.
It is a directive called
Dostları ilə paylaş: