Hello Friends, In one of my previous post related to 7 segment LED, I shared arduino codes for displaying numbers on the 7 segment LED with a time delay of 1 second. You can refer that post from here:
While writing my previous post on 7 segment LED, I wondered, if could write code for displaying alphabetical character on 7 segment LED. So in this post, I want to share with you my arduino codes using which you can see how alphabetic characters can be displayed on a 7 segment LED. This program is quite different from the program shared in the previous post because unlike the previous program on 7 segment LED wherein all the numbers were automatically displayed one by one, in this post you can see your desired character only after you press that key in the Serial Monitor. Alternatively, you can also use 'Hyperterminal' or 'Docklight' for sending data through serial port.The demo video of this experiment and the complete code is given below. You can also download the full code in a single file from this link.
Please note that the 7 segment LED is connected in common anode mode, that means all 7 anodes of leds are connected together and should be connected to +5V and a particular LED will turn on when ‘Ground’ is applied to its terminal, which in this case is done using microcontroller. (For more details on the theoretical part refer previous post on 7 segment LED).
Demo Video:
Arduino Code:
int a=2;
int b=3;
int c=4;
int d=5;
int e=6;
int f=7;
int g=8;
int p=9;
void setup()
{
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(p,OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(p,HIGH);
while(Serial.available()==0);
char letter=Serial.read();
Serial.println(letter);
switch(letter)
{
case 'A':
showa();
break;
case 'B':
showb();
break;
case 'C':
showc();
break;
case 'D':
showd();
break;
case 'E':
showe();
break;
case 'F':
showf();
break;
case 'G':
showg();
break;
case 'H':
showh();
break;
case 'I':
showi();
break;
case 'J':
showj();
break;
case 'K':
point_blink(); //indicating it is not possible to display the specified character
break;
case 'L':
showl();
break;
case 'M':
point_blink(); //indicating it is not possible to display the specified character
break;
case 'N':
point_blink(); //indicating it is not possible to display the specified character
break;
case 'O':
showo();
break;
case 'P':
showp();
break;
case 'Q':
point_blink(); //indicating it is not possible to display the specified character
break;
case 'R':
showr();
break;
case 'S':
shows();
break;
case 'T':
point_blink(); //indicating it is not possible to display the specified character
break;
case 'U':
showu();
break;
case 'V':
point_blink(); //indicating it is not possible to display the specified character
break;
case 'W':
point_blink(); //indicating it is not possible to display the specified character
break;
case 'X':
point_blink(); //indicating it is not possible to display the specified character
break;
case 'Y':
showy();
break;
case 'Z':
showz();
break;
default:
Serial.println("unknown character\nTry typing alphabets in CAPITAL");
}
}
void showa()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void showb()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void showc()
{
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
void showd()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
void showe()
{
digitalWrite(a,LOW);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void showf()
{
digitalWrite(a,LOW);
digitalWrite(b,HIGH);//high
digitalWrite(c,HIGH);//high
digitalWrite(d,HIGH);//high
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void showg()
{
digitalWrite(a,LOW);
digitalWrite(b,HIGH);//high
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);//high
}
void showh()
{
digitalWrite(a,HIGH);//high
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);//high
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void showi()
{
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
}
void showj()
{
digitalWrite(a,HIGH);//HIGH
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);//high
digitalWrite(g,HIGH);//high
}
void showl()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
void showo()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
void showp()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);//HIGH
digitalWrite(d,HIGH);//HIGH
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void showr()
{
//looks same as A
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);//high
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void shows()
{
digitalWrite(a,LOW);
digitalWrite(b,HIGH);//high
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);//high
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void showu()
{
digitalWrite(a,HIGH);//high
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}
void showy()
{
digitalWrite(a,HIGH);//high
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,HIGH);//high
digitalWrite(e,HIGH);//high
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}
void showz()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,HIGH);//high
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,HIGH);//high
digitalWrite(g,LOW);
}
void point_blink()
{
Serial.println("Not Possible to display this character");
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);//high
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);//high
digitalWrite(g,HIGH);
for(int i=0;i<20;i++)
{
digitalWrite(p,LOW);
delay(100);
digitalWrite(p,HIGH);
delay(100);
}
}