The For Loop Iteration example shows you how to light up a series of LEDs attached to pins 2 through 7 of the Arduino board, with certain limitations (the pins have to be numbered contiguously, and the LEDs have to be turned on in sequence).
This example shows you how you can turn on a sequence of pins whose numbers are neither contiguous nor necessarily sequential. To do this is, you can put the pin numbers in an array and then use for loops to iterate over the array.
This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 ohm resistors, just like in the For Loop. However, here the order of the LEDs is determined by their order in the array, not by their physical order.
This technique of putting the pins in an array is very handy. You don't have to have the pins sequential to one another, or even in the same order. You can rearrange them in any order you want.
Step 1: What You Need?
1 x Arduino Board ( Arduino UNO R3 used in this tutorial.)
6 x LEDs (RED)
6 x 220 Ohm Resistors
1 x Mini Breadboard
1 x USB Type-B Cable
Male-to-Male Jumper Wires
Connect six LEDs, with 220 ohm resistors in series, to digital pins 2-7 on your board.
1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.
6 x LEDs (RED)
6 x 220 Ohm Resistors
1 x Mini Breadboard
1 x USB Type-B Cable
Male-to-Male Jumper Wires
Optional
Don't have components? Don't worry. Just click the component's name. Step 2: Build Your Circuit.
Step 3: Upload The Code.
2. Find the port number by accessing device manager on Windows. See the section Port (COM&LPT) and look for an open port named "Arduino Uno (COMxx)". If you are using a different board, you will find a name accordingly. What matters is the xx in COMxx part. In my case, it's COM3. So my port number is 3.
Select the right port: Tools >> Port >> Select the port number.
3. You can find this code in the example of Arduino IDE.
Select File >> Examples >> 05. Control >> Arrays
Click press the "upload" button (see the button with right arrow mark).
Download:
0 comments:
Post a Comment