The
if
command looks a little
like a function definition, but this resemblance is only
superficial. The word in the parenthesis is not an argument; it is what is called
a condition
.
So in this case, the condition is that the variable
delayPeriod
has
a value that is greater
than 3,000. If this is true, then the commands inside the curly braces will be executed. In
this case, the code sets the value of
delayPeriod
back to 100.
If the condition is not true, then the Arduino will just continue on with the next thing. In
this case, there is nothing after the “if”, so the Arduino will run the
loop
function again.
Running through the sequence of events in your head will help you understand what is
going on. So, here is what happens:
1. Arduino runs
setup
and initializes the LED pin to be an output.
2. Arduino starts running
loop
.
3. The LED turns on.
4. A delay occurs.
5. The LED turns off.
6. A delay occurs.
7. Add 100 to the
Dostları ilə paylaş: