int G=6,F=5,COM1=4,A=3,B=10,DP=7,C=8,COM2=9,D=11,E=12;
int myDelay(1000);
int a=0;
void setup() {
Serial.begin(9600);
//Uppar part
pinMode(G,OUTPUT);
pinMode(F,OUTPUT);
pinMode(COM1,OUTPUT);
pinMode(A,OUTPUT);
pinMode(B,OUTPUT);
//Bottom Part
pinMode(DP,OUTPUT);
pinMode(C,OUTPUT);
pinMode(COM2,OUTPUT);
pinMode(D,OUTPUT);
pinMode(E,OUTPUT);
}
void loop() {
Serial.println("Which digit you want to display?? ");
while (Serial.available()==0)
{
}
a=Serial.parseInt();
switch(a){
case 1:
{
//CODE for 1:
for(int i=1; i<=12; i++)
{
if(i!=B && i!=C)
{
digitalWrite(i,HIGH);
/*digitalWrite(B,LOW);
digitalWrite(C,LOW);
*/
}
else{
digitalWrite(i,LOW);
}
/* add delay(1000) here to actually see and feel
how the pins are being turned off and on */
}
delay(myDelay);
break;
}
case 2:
{
//CODE for 2
for(int i=1; i<=12; i++)
{
if(i!=A && i!=B && i!=G && i!=E && i!=D)
{
digitalWrite(i,HIGH);
}
else{
digitalWrite(i,LOW);
}
}
delay(myDelay);
break;
}
case 3:
{
//CODE for 3
for(int i=1; i<=12; i++)
{
if(i!=A && i!=B && i!=G && i!=C && i!=D)
digitalWrite(i,HIGH);
else
digitalWrite(i,LOW);
}
delay(myDelay);
break;
}
case 4:
{
//CODE for 4
for(int i=1; i<=12; i++)
{
if(i!=F && i!=G && i!=B && i!=C)
{
digitalWrite(i,HIGH);
}
else{
digitalWrite(i,LOW); }
}
delay(myDelay);
break;
}
case 5:
{
//CODE for 5
for(int i=1; i<=12; i++)
{
if(i!=F && i!=G && i!=A && i!=C && i!=D)
{
digitalWrite(i,HIGH);
}
else{
digitalWrite(i,LOW); }
}
delay(myDelay);
break;
}
case 6:
{
//CODE for 6
for(int i=1; i<=12; i++)
{
if(i!=F && i!=E && i!=A && i!=G && i!=C && i!=D)
{
digitalWrite(i,HIGH);
}
else{
digitalWrite(i,LOW); }
}
delay(myDelay);
break;
}
case 7:
{
//CODE for 7:
for(int i=1; i<=12; i++)
{
if(i!=B && i!=C && i!=A)
{
digitalWrite(i,HIGH);
/*digitalWrite(B,LOW);
digitalWrite(C,LOW);
*/
}
else{
digitalWrite(i,LOW); /* declaring this else is important since
otherwise it may happen that in previous digit representation
these pins were set as HIGH and hence were not put to 'LOW' to
which is the necessary condition for this digit to be displayed
can check it for digit = 7 by removing this else part*/
}
}
delay(myDelay);
break;
}
case 8:
{
//CODE for 8
for(int i=1; i<=12; i++)
{
if(i!=COM1 && i!=COM2 && i!=DP)
digitalWrite(i,LOW);
else{
digitalWrite(i,HIGH);
} /* This else part is not required necessarliy as com1 & com 2 will
never be set to LOW (for device to work) this else only required
for decimal point to be off
*/
}
delay(myDelay);
break;
}
case 9:
{
//CODE for 9
for(int i=1; i<=12; i++)
{
if(i!=COM1 && i!=COM2 && i!=E && i!=DP)
digitalWrite(i,LOW);
else{
digitalWrite(i, HIGH);
}
}
delay(myDelay);
break;
}
default:
Serial.println("Please Enter a digit between 0 to 9 only \n");
break;
}
}