Arduino Basics
Making Light Patterns
IF Statement
The if statement is the first control structure.Here is an example of a programming using it:
listing 1.1: blink_if
int delayTime = 1000;
There is no const keyword because this is not a constant.It is a variable(which means its value can change or vary during the program).
delayTime = delayTime - 100;
Here we are changing the value of delayTime by subtracting 100 from it's original value.Since original value was 1000,after this happens the new value will be 900.
if(delayTime <= 0)
{
delayTime = 1000;
}
The purpose of this selection is to make sure the light always blinks.Since we are subtracting 100 from delayTime, we want to keep it from becoming 0 or negative.
The last section of programming turns the led on and off.
No comments:
Post a Comment