0

I am making my own "7 segment LED driver". I know there is a lot of examples on the internet, I just want to try my own. But I have a piece of code that does not work and I don't know why. Can somebody explain to me why it is not working?

When I put in this, it works:

digitalWrite(pins[0], one[0]);
digitalWrite(pins[1], one[1]);
digitalWrite(pins[2], one[2]);
digitalWrite(pins[3], one[3]);
digitalWrite(pins[4], one[4]);
digitalWrite(pins[5], one[5]);
digitalWrite(pins[6], one[6]);

So of course I tried using for():

for (byte i = 0; i >= 6; i++)
  {
    digitalWrite(pins[i], one[i]);
  }

And this does not work. But why? I think it should. Btw. pins is const byte array and one is const bool array.

Thanks in advance for any suggestions!

2
  • I don't see why it shouldn't work; what happens instead? Oct 14, 2015 at 19:23
  • The seven segment display stays off, nothing lights up; but i am sure i have it connected right, because the first code works. But the compiler doesn't give any errors....
    – user72028
    Oct 14, 2015 at 19:42

1 Answer 1

0

You've written the for loop incorrectly.

for (byte i = 0; i >= 6; i++)   <-- ERROR HERE
  {
    digitalWrite(pins[i], one[i]);
  }

That first line should be for (byte i = 0; i <= 6; i++). i begins at zero, which is less than six, and the loop only runs while i is greater than 6.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.