Programming Arduino (1) Pages 71
Programming Arduino (1) Pages 71
Now, if we look at our loop function, it has only two lines in it. We have
moved the bulk of the work off to the flash function. Notice how when we call
flash we now supply it with two arguments in parentheses.
Where we define the function at the bottom of the sketch, we have to declare
the type of variable in the parameters. In this case, they are both int s. We are in
fact defining new variables. However, these variables (numFlashes and d ) can
only be used within the flash function.
This is a good function because it wraps up everything you need in order to
flash an LED. The only information that it needs from outside of the function is
to which pin the LED is attached. If you wanted, you could make this a
parameter too—something that would be well worth doing if you had more than
one LED attached to your Arduino.
flash(x, 10);
x = 15;