[vc_row][vc_column width=”1/1″][vc_column_text]In this experiment,we will test digits 1 to 8,and auto scroll display on 7-seg LED.
The components used in this experiment are shown below:
The components are one 7-seg LED, 8 jumper wires ,and one breadboard.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Schematics” tab_id=”1392623351-1-38″][vc_column_text][/vc_column_text][/vc_tab][vc_tab title=”Wiring diagram” tab_id=”1392623351-2-66″][vc_column_text]
[/vc_column_text][/vc_tab][vc_tab title=”Arduino code” tab_id=”1392623994623-2-10″][vc_column_text]Arduino code:
//Configure the digital IO pins that used to control each segment of
the LED.
int a=7;
int b=6;
int c=5;
int d=11;
int e=10;
42 / 45
int f=8;
int g=9;
int dp=4;
//Display digit 1
void digital_1(void)
{
unsigned char j;
digitalWrite(c,LOW);
digitalWrite(b,LOW);
for(j=7;j<=11;j++)
digitalWrite(j,HIGH);
digitalWrite(dp,HIGH);
}
//Display digit 2
void digital_2(void)
{
unsigned char j;
digitalWrite(b,LOW);
digitalWrite(a,LOW);
for(j=9;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
}
//Display digit 3
void digital_3(void)
{
unsigned char j;
digitalWrite(g,LOW);
43 / 45
digitalWrite(d,LOW);
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(f,HIGH);
digitalWrite(e,HIGH);
}
//Digit 4
void digital_4(void)
{
digitalWrite(c,LOW);
digitalWrite(b,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(dp,HIGH);
digitalWrite(a,HIGH);
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
}
//Display digit 5
void digital_5(void)
{
unsigned char j;
for(j=7;j<=9;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
digitalWrite(e,HIGH);
}
//Display digit 6
void digital_6(void)
{
unsigned char j;
for(j=7;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
}
//Display digit 7
void digital_7(void)
{
unsigned char j;
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
for(j=8;j<=11;j++)
digitalWrite(j,HIGH);
}
//Display digit 8
void digital_8(void)
{
unsigned char j;
for(j=5;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
}
void setup()
{
int i;//define variable
for(i=4;i<=11;i++)
pinMode(i,OUTPUT);//set the mode of digital pins 4-11 to OUTPUT
}
void loop()
{
while(1)
{
digital_1();//display digit 1
delay(2000);//delay 2s
digital_2();
delay(2000);
digital_3();
delay(2000);
digital_4();
delay(2000);
digital_5();
delay(2000);
digital_6();
delay(2000);
digital_7();
delay(2000);
digital_8();
delay(2000);
}
}[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.