Mission 2 - Scrolling LEDs (Loop Array)
 DuinoKit Jr. - View Only. See new "Mission Manual" forum for manual and code   Started by Daniel Alich   2017-06-27 18:42:55 -04:00   Comments: 1    Viewed: 1123

  1. Daniel Alich
    Daniel Alich Member Staff Member
    252_1498603276_Mission 2-1.jpg

    252_1498603263_Mission 2-2.jpg

     
    /*
    Loop
    * Lights multiple LEDs in sequence, then in reverse.  Demonstrates
    the use of a for() loop and arrays.
    * http://www.arduino.cc/en/Tutorial/Loop
    */
    int timer = 50;                   // The higher the number, the slower the timing.
    int pins[] = { 2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers  ADDED additional pin numbers 8-11 here
    int num_pins = 10;                  // the number of pins (i.e. the length of the array)  Changed to 10

    void setup()
    {
      int i;

    for (i = 0; i < num_pins; i++)   // the array elements are numbered from 0 to num_pins - 1
        pinMode(pins[i], OUTPUT);      // set each pin as an output
    }

    void loop()
    {
      int i;
    timer=map(analogRead(A0),0,1023,1,50); // The Map function 
      for (i = 0; i < num_pins; i++) { // loop through each pin...
        digitalWrite(pins[i], HIGH);   // turning it on,
        delay(timer);                  // pausing,
        digitalWrite(pins[i], LOW);    // and turning it off.
      }
      for (i = num_pins - 1; i >= 0; i--) {
        digitalWrite(pins[i], HIGH);
        delay(timer);
        digitalWrite(pins[i], LOW);
      }
    }
     
    Daniel Alich, 2017-06-27 18:42:55 -04:00
  2. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!
Help!