Let us see if we can analyze this more carefully.
You say the display goes crazy.
What does that mean?
Is the code still running?
Does it mean that sequence of multiplexed digit is incorrect?
Or does it mean the data displayed is incorrect?
In your code you have
digit++
What is the initial and final value of digit?
Are there any limits to the value of digit?
D1-D4 are assigned values 11-14.
What are the consequences of testing for (digit == D1), for example?
Your code construct is poorly written.
Can you think of better ways of coding this?
You say the display goes crazy.
What does that mean?
Is the code still running?
Does it mean that sequence of multiplexed digit is incorrect?
Or does it mean the data displayed is incorrect?
In your code you have
digit++
What is the initial and final value of digit?
Are there any limits to the value of digit?
D1-D4 are assigned values 11-14.
What are the consequences of testing for (digit == D1), for example?
Your code construct is poorly written.
Code:
if (digit == D1)
{
digit ++;
digitalWrite(D1,LOW);
digitalWrite(D2,HIGH);
digitalWrite(D3,HIGH);
digitalWrite(D4,HIGH);
delay(wait);
}
else if (digit == D2)
{
digit ++;
digitalWrite(D1,HIGH);
digitalWrite(D2,LOW);
digitalWrite(D3,HIGH);
digitalWrite(D4,HIGH);
delay(wait);
}