![]() The value of k corresponds to the index number of elements inside the array (LED pins). As above in void setup, as we use for loop to declare all LEDS pins as OUTPUT, the same we will do in the void loop to turn LED ON and turn LED OFF using the digitalWrite() function. In the void loop, we continuously turn all LEDs ON in a sequential manner and turn OFF LEDs in opposite direction. So using while loop we have declared each LED pin of Arduino as OUTPUT In the while loop, we initialize the value of k as 0 first and later increment till the value of k reaches the total length of LED which we have declared as 10 (i = 0 to i =10). We will use a while loop to declare LED pins. ![]() Here we have 10 LEDs so instead of declaring each 10 LED pin as output. We have to declare the LED pin as output. In the void setup, we have configured the baud rate to 115200. We configure pins as INPUT or OUTPUT. ![]() We will take a small example of a while loop by glowing an led if the condition is not satisfied then the code will jump out of the while loop and the remaining code will be executed. this process is repeated until the condition is not satisfied. now again it will check in if condition whether value if i is less than 5 if condition satisfies then we will print the value of i and increment it. In the while loop first, we initialize the value of i and assign a value to it (i=0), inside the while loop we check the condition if the value of i is less than 5, if the condition satisfies then we will print the value of i and we will increment it, previously the value of i was 0 after incrementing it will change to 1. While-loop is the same as the for-loop, the result and the operationĪre similar to the for-loop but the difference is the length of the lines.
0 Comments
Leave a Reply. |