DISPLAY 1 ON SEVEN SEGMENT DISPLAY

Before display 1 on seven-segment we should understand interfacing of seven-segment and Arduino. Here we are using common cathode seven-segment. In seven-segment there are total 10 pins two are common cathode (CC) so we one is decimal point (DP) and seven led that are a, b, c, d, e, f and g.

display 1 on seven segment display

FOR COMMON CATHODE TYPE

If we want to display the number “9”, then we need to glow all the LEDs except LED which belongs to line “e” (see 7 segment pin diagram above), so we need a bit pattern 01101111 for CC display.

Similarly to display “1”we need to glow LEDs associated with b and c, so the bit pattern for this would be 00000110 for CC display. If you want decimal point led to turn on give logic ‘1’ to it and if not then ‘0’.

DIGIT TO DISPLAY DP g f e d c b a
0 0 0 1 1 1 1 1 1
1 0 0 0 0 0 1 1 0
2 0 0 1 1 1 0 1 1
3 0 1 0 0 1 1 1 1
4 0 1 1 0 0 1 1 0
5 0 1 1 0 1 1 0 1
6 0 1 1 1 1 1 0 1
7 0 0 0 0 0 1 1 1
8 0 1 1 1 1 1 1 1
9 0 1 1 0 1 1 1 1
FOR COMMON ANODE TYPE (Click Here)

Now connect Circuit as follows

Seven-Segment Arduino
A 2
B 3
C 4
D 5
E 6
F 7
G 8
CC GND
DP
Arduino Interfacing with Seven Segment
Circuit Diagram

PROGRAMMING CODE – DISPLAY 1 ON SEVEN-SEGMENT

// Display 1 on Seven Segment Display
void setup() {
  for (int i = 2 ; i <= 8 ; i++) {
    pinMode(i, OUTPUT);
  }
}
void loop() {
  one( );  //  Calling function one to display 1 on Seven Segment Display
}
void one() {
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  delay(1000);
}

CODE EXPLANATION

Hope now you understand these lines of programming code. We are assigning pin number of Arduino from two to eight as output.

void setup() {
  for (int i = 2 ; i <= 8 ; i++) {
    pinMode(i, OUTPUT);
  }
}

In void loop() we are just calling a function named one().

  • As user defined function one() is void type it will not return any value so we do not need any variable to store the return value.
  • Also user defined function one() in not parameterized so we do not need any parameter to pass in it.
  • We just need to call that function by writing one(); in the void loop() this will take the compiler to function one() and it performs the instruction written over there.
  • After all instruction executed then it will written to the void loop() where it was called and then next instructions will be executed.
  • Here it will return and not find next statement so because it is void loop() it will repeatedly call function one().
void loop() {
  one( );  //  Calling function one to display 1 on Seven Segment Display
}

It is simple as it is looking, so to display 1 we need pin number 3, 4 as high and all other pins 2, 5, 6, 7, 8 as low. Then delay the result by 1 second.

void one() {
  digitalWrite(2, LOW);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  delay(1000);
}

 

Read Next : DISPLAY 0 TO 9 ON SEVEN SEGMENT DISPLAY

Total Visits: 374
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Translate »
0
Would love your thoughts, please comment.x
()
x