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..
(had to add that to cover stupidity if any) ![]()
Thankyou for taking your time!! ![]()

