[vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Wire diagram” tab_id=”1388046025-1-64″][vc_column_text][/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1388046025-2-31″][vc_column_text]/*
code instruction:
display 1~7 in Digital Display
*/
//set the pin for controling//
int a=7;
int b=6;
int c=5;
int d=11;
int e=10;
int f=8;
int g=9;
int dp=4;
//display 1//
void digital_1()
{
unsigned char j;
digitalWrite(c,LOW);//display c segment//
digitalWrite(b,LOW);//display b segment//
for(j=7;j<=11;j++)//turn off others//
digitalWrite(j,HIGH);
digitalWrite(dp,HIGH);//turn off DP segment//
}
//display 2//
void digital_2()
{
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 3//
void digital_3()
{
unsigned char j;
digitalWrite(g,LOW);
digitalWrite(d,LOW);
for(j=5;j<=7;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
digitalWrite(f,HIGH);
digitalWrite(e,HIGH);
}
//display 4//
void digital_4()
{
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 5//
void digital_5()
{
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 6//
void digital_6()
{
unsigned char j;
for(j=7;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(c,LOW);
digitalWrite(dp,HIGH);
digitalWrite(b,HIGH);
}
//display 7//
void digital_7()
{
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 8//
void digital_8()
{
unsigned char j;
for(j=5;j<=11;j++)
digitalWrite(j,LOW);
digitalWrite(dp,HIGH);
}
//display 9//
void digital_9(void)
{
unsigned char j;
for(j=5;j<=9;j++)
digitalWrite(j,LOW);
digitalWrite(e,HIGH);
digitalWrite(dp,HIGH);
}
void setup()
{
int i;//define variable //
for(i=4;i<=11;i++)
pinMode(i,OUTPUT);//set 4~11 pin out put//
}
void loop()
{
while(1)
{
digital_1();//display 1 //
delay(2000);//delay 2s //
digital_2(); //display 2//
delay(2000); //delay 2s//
digital_3(); //display 3//
delay(2000); //delay 2s//
digital_4(); //display 4//
delay(2000); //delay 2s//
digital_5(); //display 5//
delay(2000);//delay 2s//
digital_6(); //display 6//
delay(2000); //delay 2s//
digital_7(); //display 7//
delay(2000); //delay 2s//
digital_8(); //display 8//
delay(2000);//delay 2s//
digital_9(); //display 9//
delay(2000);//delay 2s//
}
}[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.