Go Down

Topic: Possible change to the "for loop iteration - knight rider" code (Read 179 times) previous topic - next topic

Funwithautomation

Hello everyone.

I have made a small modification to the code to stop it "pausing" at each end; it looks like the first and last LED's are on for twice as long as the others (because they are :) ).
I can't figure out if this is the right place to post this, can someone please let me know if it is not. Thank you.
Code: [Select]
int timer = 100;           // The higher the number, the slower the timing.

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 >= 3; thisPin--) {
    // turn the pin on:
    digitalWrite(thisPin, HIGH);
    delay(timer);
    // turn the pin off:
    digitalWrite(thisPin, LOW);
  }
}



As you can see it is a small change, but sometimes I find those to be the most interesting :)

Go Up