void showNumber(int number){
switch(number);{
case 0 :
digitalWrite(7,HIGH);//a
digitalWrite(8,HIGH);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,HIGH);//d
digitalWrite(4,HIGH);//e
digitalWrite(6,HIGH);//f
digitalWrite(5,LOW);//g
break;
case 1 :
digitalWrite(7, LOW);//a
digitalWrite(8,HIGH);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,LOW);//d
digitalWrite(4,LOW);//e
digitalWrite(6,LOW);//f
digitalWrite(5,LOW);//g
break;
case 2:
digitalWrite(7,HIGH);//a
digitalWrite(8,HIGH);//b
digitalWrite(2,LOW);//c
digitalWrite(3,HIGH);//d
digitalWrite(4,HIGH);//e
digitalWrite(6,LOW);//f
digitalWrite(5,HIGH);//g
break;
case 3:
digitalWrite(7,HIGH);//a
digitalWrite(8,HIGH);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,HIGH);//d
digitalWrite(4,LOW);//e
digitalWrite(6,LOW);//f
digitalWrite(5,HIGH);//g
break;
case 4:
digitalWrite(7,LOW);//a
digitalWrite(8,HIGH);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,LOW);//d
digitalWrite(4,LOW);//e
digitalWrite(6,HIGH);//f
digitalWrite(5,HIGH);//g
break;
case 5:
digitalWrite(7,HIGH);//a
digitalWrite(8,LOW);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,HIGH);//d
digitalWrite(4,LOW);//e
digitalWrite(6,HIGH);//f
digitalWrite(5,HIGH);//g
break;
case 6:
digitalWrite(7,HIGH);//a
digitalWrite(8,LOW);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,HIGH);//d
digitalWrite(4,HIGH);//e
digitalWrite(6,HIGH);//f
digitalWrite(5,HIGH);//g
break;
case 7:
digitalWrite(7,HIGH);//a
digitalWrite(8,HIGH);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,LOW);//d
digitalWrite(4,LOW);//e
digitalWrite(6,LOW);//f
digitalWrite(5,LOW);//g
break;
case 8:
digitalWrite(7,HIGH);//a
digitalWrite(8,HIGH);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,HIGH);//d
digitalWrite(4,HIGH);//e
digitalWrite(6,HIGH);//f
digitalWrite(5,HIGH);//g
break;
case 9:
digitalWrite(7,HIGH);//a
digitalWrite(8,HIGH);//b
digitalWrite(2,HIGH);//c
digitalWrite(3,HIGH);//d
digitalWrite(4,LOW);//e
digitalWrite(6,HIGH);//f
digitalWrite(5,HIGH);//g
}
}
When I upload this code to TinkerCad it says case is not in switch statement and break is not within loop or switch. I didn't understand the problem.
I did a quick google search for "74hc595 7 segment 2 digit" and came up with quite a few hits.
This one looks promising:
the PIJA Ed approach uses separate 595s to individually drive each display. a more common approach is to multiplex the displays
each display requires 7 bits plus a common. multiple displays can be used by momentarily shifting the value for each display and enabling it's common. yes it requires a loop that is constantly multiplexing the displays. and yes 2 displays requires 9 bits and 2 595s, but once the code is written for 2 displays it can easily be expanded for more
each segment for each display shares a resistor. only one display segment is enabled at a time and needs to be displayed brighter that if constantly lit. if the desired segment current is 10 ma, the resistors can be chosen to allow 20 ma if the display is enabled only 50% of the time. the resistor values would be reduced proportionate to the time enabled
This forum is for help to learn coding. This forum is not for delivering ready to use code.
As soons as you post an own attempt with code and ask specific questions related to the code a neverending stream of answers will start to rush in.
If you insist on other users shall do all the work all that happend is different ways of saying the same thing as I did or simply silence.
best regards Stefan
Lose the semicolon.
a7
Thank you very much.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.