How to use an array with Arduino
This variation on the For Loop 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 example shows you how to light up a series of LEDs attached to pins 2 through 7 of the Arduino, 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 however you want.
Connect six LEDS, with 220 ohm resistors in series, to digital pins 2-7 on your Arduino.
Demonstrates the use of an array to hold pin numbers
in order to iterate over the pins in a sequence.
Lights multiple LEDs in sequence, then in reverse.
Unlike the For Loop tutorial, where the pins have to be
contiguous, here the pins can be in any random order.
* LEDs from pins 2 through 7 to ground
For more detail: How to use an array with Arduino
JLCPCB – Prototype 10 PCBs for $2 + 2 days Lead Time
China’s Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw
This Post / Project can also be found using search terms:
- arduino array project
- how to receive a array in arduino
- using arrays in arduino to cycle through random numbers