Odd 7 segment display issue

Hello

I bought a 7 segment display to play with on my new Arduino and I have a strange bug I can’t seem to find an answer too. I know I should use (and eventually will) a shift register to run this thing, but for the time being, I wanted to run it directly off of the Arduino.

This ugly code works beautifully:

int a = 0; //Anode A is the top
int b = 1; //Anode B is upper right
int dp = 12; // DP
int c = 6; //Anode C is bottom right
int d = 3; //d bottom
int e = 4; // e bottom left
int f = 5; //G middle
int g = 7; //F top left


void setup(){
  pinMode(a, OUTPUT); //Setting up pins as outputs
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(dp, OUTPUT);
}

void loop(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(dp, LOW);
  delay(100);
  digitalWrite(a, HIGH);
  delay(100);
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  delay(100);
  digitalWrite(b, LOW);
  digitalWrite(c,HIGH);
  delay(100);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  delay(100); 
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  delay(100);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  delay(100);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
  delay(100);
  digitalWrite(g, LOW);
  digitalWrite(dp, HIGH);
  delay(100);
 
}

But when I try to put all of this in an array and do essentially the same thing:

int a=0, b=1, c=6, d=3, e=4, f=5, g=7, dp= 12;
int pins[8] = {a, b, c, d, e, f, g, dp};

void setup(){
    for (int i = 0; i == 7; i++) {
    pinMode(pins[i], OUTPUT);
  }
  
}


void loop() 
{
  
  for (int i = 0; i < 8; i++) { 
    digitalWrite(pins[i], HIGH);
    delay(250);
    digitalWrite(pins[i], LOW);
    delay(250);
  }
  
  
}

It lights up anode “A” constantly, and dimly lights the rest in sequence like I expect it too. “A” never goes out.

What’s really confusing me is that I get perfect results with the first example. The segments light up clearly, and only the segment I ask to light up is lit. Nothing changes about the circuit either between the two sketches either.

Any thoughts?

for (int i = 0; i [glow]== [/glow]7; i++) {

Thanks very much :slight_smile: Changed == to < and no problem!