In this tutorial we will learn how Seven Segment display works. We have created a Up counters and Down Counters here using Seven Segment display.
You can watch the following video or read the written tutorial below.
Let see the closer look at the seven Segment display:
1 Digit Seven Segment display is contain 7 Segment and a Dot Point. It has 7 Bar-graph LEDs for 7 Segment. Each Bar-graph LEDs is denote a, b, c, d, e, f and g. These Bar-graph LEDs are activated by foreword current. Activates a certain number of Bar-graph LEDs and displays certain letters and digits.
Seven Segment displays are divided into two parts based on the connection of the Bar-graph LEDs. One is Common Cathode and other is Common Anode.
In this tutorial we have used Common Cathode Seven Segment display.
The circuit schematic is very quick sample. The Common Cathode Seven Segment display is connected to Arduino pins 2, 3, 4, 5, 6, 7 and 8. Here's we have used 100 ohm resistor witch limiting the Bar-graph LEDs forward current.
Up Counter Arduino Code:
int display[10][7] = { { 1,1,1,1,1,1,0 }, // 0
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,1,0,1,1 } // 9
};
int display_write(int);
int count;
void setup( ){
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}
void loop(){
for(count = 0; count < 10 ; count++){
display_write(count);
delay(500);
}
}
int display_write(int number){
int pin = 2 ;
for(int j = 0;j<7; j++){
digitalWrite(pin, display[number][j]);
pin++;
}
}
Code Explain:
Here's the simple Up counter Arduino code. In define section we have defined a 2 dimensional array which activate and deactivate Segment by 7 for ten characters. We have defined display_write( ) function header. Next we have defined a integer variable which name is "count".
In setup, we have set Arduino pin mode. In this case pin 2, 3, 4, 5, 6, 7 and 8 of Arduino board is an output pins.
In the main loop, we have created a for loop which increase the count variable and call the display_write( ) function. The for loop will rotate for 500 millisecond( ms ) in a row.
Here, we have create a display_write( ) function. In this function we have set the pin variable value is 2. Next, we have created a for loop witch activate and deactivate the specific segment of seven Segment display. In additional to numbers, we can display different type of character on Seven Segment display.
Down Counter Arduino Code:
int display[10][7] = { { 1,1,1,1,1,1,0 }, // 0
{ 0,1,1,0,0,0,0 }, // 1
{ 1,1,0,1,1,0,1 }, // 2
{ 1,1,1,1,0,0,1 }, // 3
{ 0,1,1,0,0,1,1 }, // 4
{ 1,0,1,1,0,1,1 }, // 5
{ 1,0,1,1,1,1,1 }, // 6
{ 1,1,1,0,0,0,0 }, // 7
{ 1,1,1,1,1,1,1 }, // 8
{ 1,1,1,1,0,1,1 } // 9
};
int display_write(int);
int count;
void setup( ){
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
}
void loop(){
for(count = 9; count >= 0 ; count--){
display_write(count);
delay(500);
}
}
int display_write(int number){
int pin = 2 ;
for(int j = 0;j<7; j++){
digitalWrite(pin, display[number][j]);
pin++;
}
}
Code Explain:
This is the Down Counter Arduino code. The Up counter and Down counter code are same but it has little deference. In Down Counter we are setting the
count variable value is 9 and we decreased the count variable value.
Click the download button for source code:
No comments