Hi forum. i want to know theoretically what delay within for loop does and also delay below for loop. also is delay after for loop mandatory. why there should be 2 delay? why not use just either within for loop or the one below the for loop. (sorry for bad grammar) thank you
void loop() {
for(int i = 165; i > 106; i--) {
topServo.write(i);
delay(2);
}
delay(500);
The first delay slows the servo down as it steps from 165 to 107. The second delay provides a pause between the servo being at 107 and the servo going back to 165.
If you read the locked posts at the top of this forum, you will learn that posting snippets of code is BAD.
I have a personal problem with using the delay(...) function. That function can be handy but wastes the considerable power of your Arduino. It would be better to learn to use millis() and not put a loop inside of the loop() function.
1 Like