Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Resistor 221 ohm
Breadboard (generic)
5 mm LED: Red
Project description
Code
ARRAYS
arduino
1/* 2 Arrays 3*/ 4 5int timer = 100; // The higher the number, the slower the timing. 6int ledPins[] = { 7 2, 7, 4, 6, 5, 3 8}; // an array of pin numbers to which LEDs are attached 9int pinCount = 6; // the number of pins (i.e. the length of the array) 10 11void setup() { 12 // the array elements are numbered from 0 to (pinCount - 1). 13 // use a for loop to initialize each pin as an output: 14 for (int thisPin = 0; thisPin < pinCount; thisPin++) { 15 pinMode(ledPins[thisPin], OUTPUT); 16 } 17} 18 19void loop() { 20 // loop from the lowest pin to the highest: 21 for (int thisPin = 0; thisPin < pinCount; thisPin++) { 22 // turn the pin on: 23 digitalWrite(ledPins[thisPin], HIGH); 24 delay(timer); 25 // turn the pin off: 26 digitalWrite(ledPins[thisPin], LOW); 27 28 } 29 30 // loop from the highest pin to the lowest: 31 for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { 32 // turn the pin on: 33 digitalWrite(ledPins[thisPin], HIGH); 34 delay(timer); 35 // turn the pin off: 36 digitalWrite(ledPins[thisPin], LOW); 37 } 38} 39
Downloadable files
Schematic Diagram
Schematic Diagram

Breadboard Diagram
Breadboard Diagram

Comments
Only logged in users can leave comments