belrey10

Lesson #5: Scrolling LED

Nov 3rd, 2024 (edited)
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.   For Loop Iteration
  3.  
  4.  Demonstrates the use of a for() loop.
  5.  Lights multiple LEDs in sequence, then in reverse.
  6.  
  7.  The circuit:
  8.  * LEDs from pins 2 through 7 to ground
  9.  
  10.  created 2006
  11.  by David A. Mellis
  12.  modified 30 Aug 2011
  13.  by Tom Igoe
  14.  
  15. This example code is in the public domain.
  16.  
  17.  http://www.arduino.cc/en/Tutorial/ForLoop
  18.  */
  19.  
  20. int timer = 100;           // The higher the number, the slower the timing.
  21.  
  22. void setup() {
  23.   // use a for loop to initialize each pin as an output:
  24.   for (int thisPin = 3; thisPin < 8; thisPin++) {
  25.     pinMode(thisPin, OUTPUT);
  26.   }
  27. }
  28.  
  29. void loop() {
  30.   // loop from the lowest pin to the highest:
  31.   for (int thisPin = 3; thisPin < 8; thisPin++) {
  32.     // turn the pin on:
  33.     digitalWrite(thisPin, HIGH);
  34.     delay(timer);
  35.     // turn the pin off:
  36.     digitalWrite(thisPin, LOW);
  37.   }
  38.  
  39.   // loop from the highest pin to the lowest:
  40.   for (int thisPin = 7; thisPin >= 3; thisPin--) {
  41.     // turn the pin on:
  42.     digitalWrite(thisPin, HIGH);
  43.     delay(timer);
  44.     // turn the pin off:
  45.     digitalWrite(thisPin, LOW);
  46.   }
  47. }
Add Comment
Please, Sign In to add comment