Friday, July 22, 2016

Filled Under: , ,

Arrays

05. Control Arrays library

This variation on the For Loop Iteration example shows how to use an array. An array is a variable with multiple parts. If you think of a variable as a cup that holds values, you might think of an array as an ice cube tray. It's like a series of linked cups, all of which can hold the same maximum value.

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 


Don't have components? Don't worry. Just click the component's name. 


Step 2: Build Your Circuit.



Connect six LEDs, with 220 ohm resistors in series, to digital pins 2-7 on your board.


Step 3: Upload The Code.



1. Select the Arduino board type: Select Tools >> Board >> Select your correct Arduino board used.


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: 


Unknown

Author & Editor

My Robot Education Sdn. Bhd. (Robotedu.my) was founded in 2015 as the first robotics education centre in Malaysia to provide Arduino-based robotics courses for youths. Our vision is to be able to provide robotics education to every youth in Malaysia.

0 comments:

Post a Comment

 

  • Copyright © Arduino Tutorial ™ is a registered trademark.
    Designed by Templateism. Hosted on Blogger Templates.