Cant display 8 on my digit display when given the time interval!!

This is a simple program… to count numbers 0 to 9 on a digit display… Using a Arduino UNO and a 7-segment digit display.

What it is supposed to do: Count numbers 0 to 9 with a interval of 1 second in between (without switching off the display. i.e. continuously)…

What it is doing: Counting from numbers 0 to 7 with 1s delay, perfectly without and problems, skipping 8… i.e. giving 2s delay between 7 and 9 and continues to 9 and back to 0… The problem hence lies in displaying the number 8… It shows no problems displaying 8 without the time delay… i.e. showing 8 continuously…

The connections I gave are shown in the picture i have attached…
The Physical connections are also shown in the next picture… Although I feel there are no issues in the connections… I feel the problem lies in the coding I gave…

I am new to this… I am not attending any classes… I am a highschool kid… So forgive me if this seems too unprofessional… I hav not used any predefined libraries… I did the dis() function myself… U can see that clearly in the code below…

int i=0,X;

void setup() //just to defining the output ports
{
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
}

void onE(int d) // onE and on are the same… they were different before… to experiment on why this problem occured.
{
digitalWrite(d,HIGH);
}
void on(int d)
{
digitalWrite(d,HIGH);
}
void off(int d)
{
digitalWrite(d,LOW);
}

void Dis(int b,int a=7) // function to define the ports i need to be turned on to display various digits [0 to 9]
{
off(a);
b+=1; // didnt know if ‘case’ could take values of 0 so i just incremented the digit to be displayed by 1.
switch(b)
{
case 1: onE(1);onE(2);onE(3);onE(4);onE(5);onE(6);break;
case 2: onE(3);onE(4);break;
case 3: onE(0);onE(2);onE(3);onE(5);onE(6);break;
case 4: onE(0);onE(2);onE(3);onE(4);onE(5);break;
case 5: onE(0);onE(1);onE(3);onE(4);break;
case 6: onE(0);onE(1);onE(2);onE(4);onE(5);break;
case 7: onE(0);onE(1);onE(2);onE(4);onE(5);onE(6);break;
case 8: onE(2);onE(3);onE(4);break;
case 9: onE(0);onE(1);onE(2);onE(3);onE(4);onE(5);onE(6);onE(7);onE(8);onE(9);break;
case 10: onE(0);onE(1);onE(2);onE(3);onE(4);onE(5);break;
}
}

void loop()
{
i++;
if(i==10)i=0;
off(0);off(1);off(2);off(3);off(4);off(5);off(6);off(7);off(8);off(9); //resetting all ports to low to display the next digit
X=i;
Dis(X);
delay(1000);
}

Please do tell me if there are any additional components I need to add to the circuit to ensure the safety of the digit display…

I am a noob… :smiley: (had to add that to cover stupidity if any) :slight_smile:
Thankyou for taking your time!! :slight_smile:

  1. Not a good idea to use pins 0 and 1 as they are the serial comms pins. Start at 2.
  2. The case statement can take any values, including 0 and negative.
void Dis(int b,int a=7)  // function to define the ports i need to be turned on to display various digits [0 to 9]
{
 off(a);
 b+=1;  // didnt know if 'case' could take values of 0 so i just incremented the digit to be displayed by 1. 
 switch(b)
{

The only difference between an 8 and a 9 is one LED segment - could this be connected to output 7 which you are ALWAYS turning OFF in the code above (for no real reason that I can see)?

Also, post your code using the # not the quotation. It makes it easier to read.

Reading the start of your code, you have if I = 10 then I = 0, when I should read I= 1. you don't have a case 0 and two lines up, you are making sure that I ++ so I automatically starts at 1. and you might as well go with Dis(I) instead of x=I; and then dis(x);

As I said, theres nothing wrong with the segments and port connections that have to turn on to display a digit.. And thanks for the tip on the case part.. I was taught C++ in high school.. Never used "case 0: " or "case -1: " before... When everything except the void loop remains unchanged and I replace the loop() with the following code:

void loop()
{
Dis(8);
delay(1000);
}

[note: I havnt given the command to reset all ports.. (the code line: off(0);off(1);off(2);....off(9);)] I get a brief flash of 8 and then a blank display.. could there be a problem with the digit display? I bought 5 such displays of the same manufacturer.. All show this same output.. A BLANK SCREEN!!!

Again just to be clear: For the loop() function to display just 8 WITHOUT THE DELAY:

void loop()
{
 Dis(8);
}

I get a good clear output of 8..

Please do tell me if there are any additional components I need to add to the circuit to ensure the safety of the digit display

I notice in the circuit that you do not have any resistors in series with the LED. You will end up damaging the LED or the Arduino output as the current drawn will be too high. You need to put a series R with the LED. I would suggest something like 470 Ohm to start with as a safe value. There are lots of resources to tell you how to calculated the R for your LED, it comes up often in these forums.

Also, rereading

off(0);off(1);off(2);off(3);off(4);off(5);off(6);off(7);off(8);off(9);

your outputs are pins 0..7 and do not include 8 and 9.

Maybe your LEDs or the Arduino ports are shutting down. with a delay you would notice the 'flash'. Without the delay you are continuously turning them on again and again. If the delay is much shorter (say 20 ms) do they appear dim?

Your lettering of the segments is wrong, making it a trifle difficult to check the digit patterns. There is a standard way of denoting them.

        _a_
      /   /
   f /_g_/ b
    /   /
 e /___/ c
    d

While you are at it, go back and "modify" your first post to correct the "quote" tags to "code".

Now, whilst your circuit proposes to have the common cathode of the 7-segment display grounded, you photograph suggests it is in fact connected to an Arduino (output) pin and you have an eighth pin defined, presumably as the decimal. I have a funny suspicion that you have been fiddling with the wiring and the code trying to get it to work with this wiring mistake and actually have the common cathode connected to that eighth pin which you are setting high in your muddled case 9 which is pulling the common cathode (which is in all other cases pulled low and sinking the current for all the segments) high and - blanking the display.

You need to pull it apart - I suggest you re-do your wiring to match the standard pattern, put in the 470 ohm resistors and clean up the code to match (use pins starting at 2, re-do the segment patterns, "case" starting at zero), connect the cathode pin to an actual ground, and you should be in business.

I don't know what int i=0,X; means either.

Sorry guys.. This was an awfully careless mistake.. Anyways, the solution is the mistake i made on the line for "case 9:"(recall that I didnt know if I could use 0 for case so I had to increment all digits I wantd to display by 1 so, to display the number 8, I had to look at "case 9: " I had included that extra 3 commands:

onE(7);onE(8);onE(9);

and as mentioned earlier by one of u guys, the 'off' command also had 3 extra ones..

off(7);off(8);off(9);

Anyway, thank yall for taking your time reading this! And I also wanted to ask this also.. As I said earlier, I am a beginner.. what is the next step?!! I learnt digital I/O.. What I feel is the basics.. What to do next? Shud I move to Analogue? theres lots of libraries to learn from.. Where do I start?! I know C++.. All the programming I have done so far is basically C++ right?.. Again.. WHAT SHUD I DO NEXT AND WHERE DO I START?!

There are a bunch of basics that you need to get under your belt - Dealing with digitals - reading/writing, pullup/pulldown resistors, using switches - Dealing with analogs - reading/writing, PWM, voltage dividers (dealing with a whole class of sensors) - Using the Serial output for debugging - Learning how to do lots of things without pausing (no delay()) - see blink without delay and learn that technique - Learn about Finite State Machine style programming

Then it depends on what your interests are - find a project and put it all together into something useful.

The blinking without the delay thingy.. thats multiplexing... Am I right?! I am right now trying to do a digital clock.. Now its working.. I mean I am able to multiplex two digit displays and make them count to 60 and then reset.. Still hav two other displays to attach to make up for the hours.. Next I wanna work with RF communication.. Too ambitious?! :D Or will I be going in the right direction?! :|

Blinkwithoutdelay is more multitasking than multiplexing.

Perhaps you might just reassure us that you have in fact, re-wired and re-coded it (successfully).

And fix the mark-up on your first post. :D