user69220: int timer = 1000;
int thispin = 5;

void setup() {
  for (int thispin = 5; thispin < 8; thispin++) 
    pinMode(thispin, OUTPUT);
}

void loop() {
  for (int thispin = 5; thispin < 8; thispin++) 
    digitalWrite(thispin, HIGH);

  delay(timer);
  digitalWrite(thispin, LOW);


  for (int thispin = 7; thispin = 5; thispin--) 
    digitalWrite(thispin, HIGH);

  delay(timer);
  digitalWrite(thispin, LOW);
}

I have the above code. I thought that how it was written would cause the led's to flash but they all stay on continuously. Could anybody help to explain what it is i have done wrong?
I am very new to this and I'm just fiddling basically trying to learn.
Thank you!

user68923: From the given code it is not entirely clear what you are trying to achieve.
If I understood correctly, you want the pins to light up for one second and then go out. First from 5 to 7, and then from 7 to 5.
Try the given code.
int timer = 1000;

void setup() 
{
  for (int thispin = 5; thispin < 8; thispin++) 
    pinMode(thispin, OUTPUT);
}

void loop() 
{
  for (int thispin = 5; thispin < 8; thispin++)
  { 
    digitalWrite(thispin, HIGH);
    delay(timer);
    digitalWrite(thispin, LOW);
  }

  delay(timer);

  for (int thispin = 7; thispin >= 5; thispin--) 
  {
    digitalWrite(thispin, HIGH);
    delay(timer);
    digitalWrite(thispin, LOW);
  }
}

Also, using the same name for globals variable and  loop iterators is bad style.

user63264: The objective of the code is not clear. It seems the idea is to repeatedly blink 3 LEDs, connected on pins 5,6 and 7. To do so, the code needs slight modification-
int timer = 1000;
int thispin = 5;

void setup() {
  
  for (int thispin = 5; thispin < 8; thispin++) 
    pinMode(thispin, OUTPUT);
}

void loop() {
  
  for (int thispin = 5; thispin < 8; thispin++) 
    digitalWrite(thispin, HIGH); 
 
    delay(timer); 

  
  for (int thispin = 5; thispin < 8; thispin++) 
    digitalWrite(thispin, LOW);

    delay(timer); 

}

Also, since you wanted to know why the LEDs stay ON continuously with your code-
This is because there is no delay statement after any of the digitalWrite-LOW statements. If there's no delay, the LEDs may turn off for a fraction of a millisecond, which won't be noticeable.

69220: 
<pre class="lang-c++ prettyprint-override"><code>int timer = 1000;
int thispin = 5;

void setup() {
  for (int thispin = 5; thispin &lt; 8; thispin++) 
    pinMode(thispin, OUTPUT);
}

void loop() {
  for (int thispin = 5; thispin &lt; 8; thispin++) 
    digitalWrite(thispin, HIGH);

  delay(timer);
  digitalWrite(thispin, LOW);


  for (int thispin = 7; thispin = 5; thispin--) 
    digitalWrite(thispin, HIGH);

  delay(timer);
  digitalWrite(thispin, LOW);
}
</code></pre>
<p>I have the above code. I thought that how it was written would cause the led's to flash but they all stay on continuously. Could anybody help to explain what it is i have done wrong?
I am very new to this and I'm just fiddling basically trying to learn.
Thank you!</p>
 68923: <p>From the given code it is not entirely clear what you are trying to achieve.
If I understood correctly, you want the pins to light up for one second and then go out. First from 5 to 7, and then from 7 to 5.
Try the given code.</p>
<pre><code>int timer = 1000;

void setup() 
{
  for (int thispin = 5; thispin &lt; 8; thispin++) 
    pinMode(thispin, OUTPUT);
}

void loop() 
{
  for (int thispin = 5; thispin &lt; 8; thispin++)
  { 
    digitalWrite(thispin, HIGH);
    delay(timer);
    digitalWrite(thispin, LOW);
  }

  delay(timer);

  for (int thispin = 7; thispin &gt;= 5; thispin--) 
  {
    digitalWrite(thispin, HIGH);
    delay(timer);
    digitalWrite(thispin, LOW);
  }
}
</code></pre>
<p>Also, using the same name for globals variable and  loop iterators is bad style.</p>
 63264: <p>The objective of the code is not clear. It seems the idea is to repeatedly blink 3 LEDs, connected on pins 5,6 and 7. To do so, the code needs slight modification-</p>
<pre><code>int timer = 1000;
int thispin = 5;

void setup() {
  
  for (int thispin = 5; thispin &lt; 8; thispin++) 
    pinMode(thispin, OUTPUT);
}

void loop() {
  
  for (int thispin = 5; thispin &lt; 8; thispin++) 
    digitalWrite(thispin, HIGH); 
 
    delay(timer); 

  
  for (int thispin = 5; thispin &lt; 8; thispin++) 
    digitalWrite(thispin, LOW);

    delay(timer); 

}
</code></pre>
<p>Also, since you wanted to know why the LEDs stay ON continuously with your code-
This is because there is no delay statement after any of the digitalWrite-LOW statements. If there's no delay, the LEDs may turn off for a fraction of a millisecond, which won't be noticeable.</p>
