0% found this document useful (0 votes)
22 views

2 Loop Led

This code uses for loops to light up multiple LEDs connected to pins 2 through 7 on an Arduino board in sequence and then in reverse. It initializes each pin as an output in a for loop during setup. The main loop contains two for loops, one counting up to light the LEDs from pin 2 to pin 7, and one counting down to light them from pin 7 to pin 2.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

2 Loop Led

This code uses for loops to light up multiple LEDs connected to pins 2 through 7 on an Arduino board in sequence and then in reverse. It initializes each pin as an output in a for loop during setup. The main loop contains two for loops, one counting up to light the LEDs from pin 2 to pin 7, and one counting down to light them from pin 7 to pin 2.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Loop led

/* For Loop Iteration Demonstrates the use of a for() loop. Lights multiple LEDs in sequence, then in reverse. The circuit: * LEDs from pins 2 through 7 to ground

This example code is in the public domain. http://www.arduino.cc/en/Tutorial/ForLoop */

int timer = 100; timing.

// The higher the number, the slower the

void setup() { // use a for loop to initialize each pin as an output: for (int thisPin = 2; thisPin < 8; thisPin++) { pinMode(thisPin, OUTPUT); } } void loop() { // loop from the lowest pin to the highest: for (int thisPin = 2; thisPin < 8; thisPin++) { // turn the pin on: digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); } // loop from the highest pin to the lowest: for (int thisPin = 7; thisPin >= 2; thisPin--) { // turn the pin on: digitalWrite(thisPin, HIGH); delay(timer); // turn the pin off: digitalWrite(thisPin, LOW); } }

You might also like