From the course: Learning Arduino: Interfacing with Hardware

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Cycle through LEDs with a for loop

Cycle through LEDs with a for loop - Arduino Tutorial

From the course: Learning Arduino: Interfacing with Hardware

Cycle through LEDs with a for loop

- So in the previous video, we kind of copy and paste a lot of the code so let's try to use a for loop in order to reduce the code that we tried in the previous example. Since we did the wiring for the Arduino board, from two all the way to eight, so we can take advantage of using a for loop where we can start from two all the way to eight. So let's see how we can do that in the coding parts. So I'll give it a start in here. On line 13 all the way to line 19, the only thing that's being changed is the LED parts. So you notice here it's A, B, C, D. So since we do the wiring from two all the way to eight, so we can use a for loop. So in the for loop, I'm going to go ahead and initialize a starting point. I'll name it equals to two because the pins are connected from two. And then I is less than nine because I want the number to stop at eight. And then finally the increment would be just one. Now inside the for loop, I…

Contents