There are other ways of harnessing the power of computers to complete repetitive tasks.
This block of code sits in the void loop. It will be executed as long as the conditions in the parenthesis is true. As the program progresses and we get to the while we ask the question, "Is ledPin greater than or equal to 9?" If yes, then we do the code in the curly brackets. Then we ask the question again, if true we execute the code again. This keeps repeating until the answer is "no". Then the program continues on. Note, whatever variable is being checked must be changed within the while otherwise once the while loop starts it will never end.
This looks almost identical to the IF Loop we did in the last lesson. The "IF Loop" works as long as its the only thing you're doing in your void loop. However, what if you wanted to do something before or after you sequentially light your LEDs. In this case you could use a While statement. In fact you should be able to use this to make your LED sequencer go back and forth. This is not something you could do with your IF loop.
Comparison Operators:
As you might guess this involves comparing two values to each other. This might be useful when setting conditions for your while. Mostly this is straight forward but here it is anyway:
The operator that is most important to mention is "x is equal to y". The double equals sign is not a typo. A double equal sign is used to ask the question, does x equal y. If I used a single equals sign "x=y" I would be saying set the value of x to be the value of y. This difference is very important.
Additional Tasks:
|