0% found this document useful (0 votes)
9 views

Programming Arduino (1) Pages 69

Uploaded by

axl1994
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Programming Arduino (1) Pages 69

Uploaded by

axl1994
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

{

digitalWrite(ledPin, HIGH);

delay(delayPeriod);

digitalWrite(ledPin, LOW);

delay(delayPeriod);

So, all we have really done here is to move the four lines of code that flash
the LED from the middle of the for loop to be in a function of their own called
flash . Now you can make the LED flash any time you like by just calling the
new function by writing flash() . Note the empty parentheses after the function
name. This indicates that the function does not take any parameters. The delay
value that it uses is set by the same delayPeriod variable that you used before.

Parameters
When dividing your sketch up into functions, it is often worth thinking about
what service a function could provide. In the case of flash , this is fairly obvious.
But this time, let’s give this function parameters that tell it both how many times
to flash and how short or long the flashes should be. Read through the following
code and then I will explain just how parameters work in a little more detail.
// sketch 4-02

const int ledPin = 13;

const int delayPeriod = 250;

You might also like