top of page

Work With Arduino


3. For loop with Arduino

The Arduino for loop provides a mechanism to repeat a section of code depending on the value of a variable. So you set the initial value of the variable, the condition to exit the loop (testing the variable), and the action on the variable each time around the loop.


Programe

int led = 11; int timer = 100; void setup () { pinMode(led,OUTPUT); } void loop() { for (int i = 0; i < 255;i++) { analogWrite(led,i); delay(timer); } for (int i = 255;i > 0;i--) { analogWrite(led,i); delay(timer); } } What is the for () statement used for? The for statement lets you repeat a statement or compound statement a specified number of times. The body of a for statement is executed zero or more times until an optional condition becomes false. What does void setup mean Arduino? Void setup and void loop The code that you put inside void setup() will only run once, and that will be at the beginning of your program. One example is when you want to turn your robot on — that does not happen multiple times! In void loop(), your code will repeat over and over again.



16 views0 comments

Recent Posts

See All

Comments


bottom of page