Things Needed :
Arduino UNO
7-Segment single digit(any color)
A 7-segment display is a one which contains 7 LEDs named a,b,c,d,e,f,g. By turning ON and OFF particular LED we can display a digit using it.
There are two types of 7-segment digit like common cathode and common anode. In common cathode all the 7 LEDs cathode pins are connected together (in simple terms it have common cathode). In common anode all the 7 LEDs cathode pins are connected together (in simple terms it have common anode)Here we used common cathode.
For this we have to know some of the basic things about digital electronics like binary, octal, hexadecimal, decimal.
Here we used a single digit 7-segment digit. In order to make things easier, we are taking the hexadecimal values of the digit to be displayed in the 7-segment digit using Arduino.
In Arduino there are three ports of Input and Output pins like Port A, Port B, etc.
If we want to connect the 7-segment LED to the Arduino make sure all the 7 pins are connected in the same Port. Example Port A have 0 - 7 digital pins then you have to connect all the pins of the 7-segment LED to the same port A. If you mismatch the pin in different ports it won't work.
After connecting all the components, now its time for the code section.
In the code we just declare the pinmode function output state of all the 7 pins of the 7-segment LED.
After that in the loop section we have to just give the command PORTD = 0x3f.
In 0x3f, ''x" represents the hexadecimal, "b" states for binary.. and etc etc..
The below code shows the output that it displays the number from 0 to 1 with a delay of 1000.
In the void setup we have to declare all the 7 LED pins as OUTPUT. (Note : All the 7 pins are in the same PORT like here I used PORTD).
In the loop section I simply wrote the command PORTD with an operator "=" the hexadecimal value of the number as the next....
PROGRAM CODE
void setup() {
int i;
for(i=0;i<=7;i++){
pinMode(i,OUTPUT);
}
}
void loop() {
PORTD=0x3f;
delay(1000);
PORTD=0x06;
delay(1000);
PORTD=0x5B;
delay(1000);
PORTD=0x4F;
delay(1000);
PORTD=0x66;
delay(1000);
PORTD=0x6D;
delay(1000);
PORTD=0x7D;
delay(1000);
PORTD=0x07;
delay(1000);
PORTD=0x7F;
delay(1000);
PORTD=0x67;
delay(1000);
}
Here 3f represents the hexadecimal value of the decimal number 3.
Have fun :)
0 Comments