Table of Contents
Before displaying 1 on seven-segment we should understand the interfacing of seven-segment and Arduino. Here we are using a common cathode seven-segment. In the seven-segment there are a total 10 pins, two are common cathode (CC), one is decimal point (DP) and seven LEDs that are a, b, c, d, e, f and g.
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 a 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 | – |
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 the 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() is 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 instructions are executed then it will be written to the void loop() where it was called and then the next instructions will be executed..
- Here it will return and not find the 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