Need help :)

Hey , I tried to count to 30 using 2x bcd converters , 2x single seven segment displays . I will count to 9 on the first segment display which will increase the next by 1 each timeit hits 9 . I try to use the array command , and I am stuck as I can not get the second display to increase by one each time the first display comes to 9. I'm pretty new to this so any help would be appreciated . here is my coding so far.

int segPin[]={
5,6,7,8};
int segPin2[]={
1,2,3,4};

int maxcount = 10;
int delayInterval = 500;

void setup()
{
for (int i=0; i<4; i++)
{
pinMode (segPin*,OUTPUT);*

  • }*
  • for (int a=0; a<4; a++)*
  • {*
  • pinMode (segPin2[a],OUTPUT);*
  • }*
    }
    void loop()
    {
  • for (int counter=0; counter<maxcount; counter++)*
    {
  • displayBinary(counter);*
  • delay(delayInterval);*
    }
    }
    void displayBinary (byte numToShow)
    {
  • for (int i=0; i<4; i++)*
  • {*
  • if(bitRead (numToShow,i)==1)*
  • {*
    _ digitalWrite(segPin*,HIGH);_
    _
    }_
    _
    else*_
    * {*
    _ digitalWrite(segPin*,LOW);
    }*_

}
}

The code you have posted doesn't even compile. and never will

you declare the global variable

int segPin[]={
  5,6,7,8};

Yet in your setup you have

 pinMode (segPin,OUTPUT);

Obviously this should have been pinMode (segPin [i],OUTPUT);
Nevertheless, it's not good form to post code that is obviously not what you're using.

I'll bet that you wanted this code:

for (int i=0; i<4; i++)
{
pinMode (segPin*,OUTPUT);*

  • }*

to look like this:

  for (int i=0; i<4; i++)
    {
      pinMode (segPin[i],OUTPUT);
   
    }

The code is displayed improperly because the forum uses an "i" in brackets to indicate that the following text should be displayed in an italic font. The way to avoid this is to post code inside [ code ] tags.

Please read the sticky post, "How to use this forum - please read," shown at the top of the list of posts in each section of the forum. Please note, however, that the forum software has been updated since that sticky post was written, and the icon for code tags doesn't look the same. Instead of a hashtag, "#", it looks like a little scroll with a blue star. See the tiny attached image.

You'll find a lot of other information in that sticky post that will help you build posts that are more effective, in terms of communicating your intent, and in terms of inspiring others to respond with something that will help you.

That said, after making what appear to me to be the appropriate corrections in the sketch, it looks like loop() only counts to 9, and then starts over. I don't see anything that tries to count past 9. Maybe you could correct your code, or repost it properly, and explain a bit more about what you're trying to do?

CodeTagIcon.JPG